我有一个滚动视图,仅限于垂直滚动。在它的内部,我希望有一个UIPanGestureRecognizer的视图,只识别水平平底锅。
同样,水平识别器赢了,并防止滚动视图滚动。
我希望水平平底锅,如果它检测到一个主要的水平姿态,否则垂直滚动将获胜。非常类似于邮箱的工作方式,或在iOS8 Mail.app中滑动
发布于 2014-11-30 23:30:09
您可以使用UIGestureRecognizerDelegate方法之一(如gestureRecognizerShouldBegin: )来指定在哪种情况下触发pan手势。
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
// If the gesture is a pan, determine whether it starts out more
// horizontal than vertical than act accordingly
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]) {
UIPanGestureRecognizer *panGestureRecognizer = (UIPanGestureRecognizer *)gestureRecognizer;
CGPoint velocity = [panGestureRecognizer velocityInView:self.view];
if (gestureRecognizer == self.scrollView.panGestureRecognizer) {
// For the vertical scrollview, if it's more vertical than
// horizontal, return true; else false
return fabs(velocity.y) > fabs(velocity.x);
} else {
// For the horizontal pan view, if it's more horizontal than
// vertical, return true; else false
return fabs(velocity.y) < fabs(velocity.x);
}
}
else
return YES;
}https://stackoverflow.com/questions/27195236
复制相似问题