我有 UIView 并附加了一个 UIPanGestureRecognizer 。
在 UIView 我有 UIScrollView 启用了分页,我设置了内容大小,所以 scrollView 可以滚动 到左边。
问题:
我希望当用户尝试将 scrollView 向右拖动时,将事件向上发送到 UIView,以便 'UIPanGestureRecognizer' 可以处理触摸事件
Best Answer-推荐答案 strong>
终于,6 小时后我弄明白了
我继承了 UIScrollView 并实现了 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer 委托(delegate)方法
当用户拖动 ScrollView 时,此方法被调用 (BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer ,默认返回 NO
- (BOOL)gestureRecognizerUIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizerUIGestureRecognizer *)otherGestureRecognizer{
if (self.contentOffset.x > 0 && self.contentOffset.x <= self.contentSize.width - self.frame.size.width) {
//user is in middle of dragging the scrollView don't allow any other gestureRecognizer to respond
return NO;
}else{
//scrollView contentOffset is 0 and user is not dragging the scrollView so let other gestureRecognizer to respond
return YES;
}
}
关于ios - 禁用 UIScrollView 拖动事件到特定方向并将事件发送到 super ,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/18704244/
|