我有一个UIScrollView,其框架与包含视图控制器相同。
当滚动视图的缩放比例大于1时,从屏幕左侧50%开始从左向右滑动会导致interactivePopGestureRecognizer激活并关闭视图控制器。 这仅在设备处于横向状态时才会发生。它在纵向时工作正常。
使用scrollview使这个手势正常工作是否需要特殊处理?
答案 0 :(得分:2)
1,将interactivePopGestureRecognizer委托设置为self(Custom UINavigationController)
self.interactivePopGestureRecognizer.delegate = self;
2,启用同时识别UIScrollView UIGestureRecognizer
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.interactivePopGestureRecognizer == gestureRecognizer) {
if ([otherGestureRecognizer.view isKindOfClass:UIScrollView.class]) {
UIScrollView *scrollView = (UIScrollView *)otherGestureRecognizer.view;
if ((scrollView.contentSize.width > CGRectGetWidth(self.view.bounds) && scrollView.contentOffset.x == 0)) {
return YES;
}
}
}
return NO;
}
答案 1 :(得分:0)
第1步: @implementation UIScrollView(AllowPanGestureEventPass)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]]
&& [otherGestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]])
{
return YES;
}
else
{
return NO;
}
}
第2步:
[_scrollView.panGestureRecognizer requireGestureRecognizerToFail:screenEdgePanGestureRecognizer];