他の解決策を調べましたが、自分に適した解決策を見つけることができません。大きな写真を表示するUIImageView
内に があります。UIScrollView
UIScrollView
左と右のスワイプジェスチャレコグナイザーと同様に、ピンチジェスチャを有効にしています。
現在、スクロールビューのパン ジェスチャは、スワイプ ジェスチャを無効にする (または破損する) ようです。で水平スクロールまたは垂直スクロールを無効にしたくありませんUIScrollView
。写真の最初のスケーリングが大きすぎて、水平スクロールを無効にできません。
私がやりたいことは、UIScrollView の端に来たときにスワイプ ジェスチャをトリガーすることです。
ここにいくつかのコードがあります。
- (void)viewDidLoad
{
// recognizer for pinch gestures
UIPinchGestureRecognizer *pinchRecognizer =[[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(handlePinch:)];
[self.myScrollView addGestureRecognizer:pinchRecognizer];
[self.myScrollView setClipsToBounds:NO];
// recognizer for swipe gestures
UISwipeGestureRecognizer *recognizer;
// left and right swipe recognizers for left and right animation
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleLeftSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionRight)];
[[self myScrollView] addGestureRecognizer:recognizer];
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightSwipe:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[[self myScrollView] addGestureRecognizer:recognizer];
....
私の左スワイプハンドラー、現在、左と右のスワイプには追加機能がありません
-(void)handleLeftSwipe:(UISwipeGestureRecognizer *)recognizer
{
if(!self.tableView.hidden) self.tableView.hidden = YES;
[self showRequiredStuff];
CATransition *transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype =kCATransitionFromLeft;
transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];
私の初期画面サイズ。
#define IMAGE_VIEW_WIDTH 320.0
#define IMAGE_VIEW_HEIGHT 384.0
写真のスケーリングを使用して、可能な限り小さくスケーリングしますが、それらのほとんどは幅の広い画像であり、水平スクロールが有効になっており、垂直スクロールが無効になっています。私のスワイプハンドラーも水平ですが。
何が起こっているのか、何が必要なのかを明確に説明したと思います。私は iPhone アプリケーション開発の初心者なので、コードを投稿しました。他の人ができるだけ多くのコードを見るのを助けたいと思っています。また、誰かが悪いプログラミングを指摘してくれるかもしれません。
関連するソリューションからの追加の調査結果; 設定後
@interface myViewController () <UIScrollViewDelegate>
と
self.myScrollView.delegate = self;
水平にエッジに到達したかどうかを検出する
- (BOOL) hasReachedAHorizontalEdge {
CGPoint offset = self.myScrollView.contentOffset;
CGSize contentSize = self.myScrollView.contentSize;
CGFloat height = self.myScrollView.frame.size.height;
CGFloat width = self.myScrollView.frame.size.width;
if ( offset.x == 0 ||
(offset.x + width) == contentSize.width ) {
return YES;
}
return NO;
}
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
if ( [self hasReachedAHorizontalEdge] ) {
NSLog(@"Reached horizontal edge.");
// required here
}
}
この時点で、到達した端でスクロールを無効にする必要があるだけです。スクロールの右端に到達した場合は、右スクロールのみを無効にする必要があります。そうすれば、スワイプがトリガーされます。