次のようなUIPanGestureRecognizer
セットアップを追加しました。gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
if ([gestureRecognizer isEqual:self.panGesture] && [otherGestureRecognizer isEqual:self.collectionView.panGestureRecognizer]){
return YES;
}
return NO;
}
チェックインも追加しましたgestureRecognizerShouldBegin:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.panGesture]) {
if (gestureRecognizer.numberOfTouches > 0) {
CGPoint point = [gestureRecognizer locationOfTouch:0 inView:gestureRecognizer.view];
CGFloat distX = abs(self.collectionView.lastTouchPos.x - point.x);
CGFloat distY = abs(self.collectionView.lastTouchPos.y - point.y);
if (distX > distY) {
return NO;
}
} else {
return NO;
}
}
return YES;
}
self.panGesture
上または下にパンする場合にのみ使用します。
アップデート
https://stackoverflow.com/a/8603839/667834には、より良い方法があるようですgestureRecognizerShouldBegin
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer isEqual:self.panGesture]) {
if (gestureRecognizer.numberOfTouches > 0) {
CGPoint translation = [self.panGesture velocityInView:self.collectionView];
return fabs(translation.y) > fabs(translation.x);
} else {
return NO;
}
}
return YES;
}