在为同级视图启用手势识别器的情况下,将 UIView 拖动到 UIScrollView 内
我的应用程序中有以下视图层次结构:
-- UIScrollView (canCancelContentTouches is NO)
-- UIView #1 (UISwipeGestureRecognizer is bound to it to track horizontal swipes)
-- UIView #2 (touchesBegan/touchesMoved/touchesEnded are implemented here to allow
dragging this view inside its parent; implementation is very
straightforward and I'm NOT calling supermethods here).
当我开始拖动视图 #2 时,它有时会触发滑动手势识别器。我实在看不出其中的规律,但这种情况经常发生。
有什么办法可以抑制拖动时的触摸处理吗?
I have a following view hierarchy in my app:
-- UIScrollView (canCancelContentTouches is NO)
-- UIView #1 (UISwipeGestureRecognizer is bound to it to track horizontal swipes)
-- UIView #2 (touchesBegan/touchesMoved/touchesEnded are implemented here to allow
dragging this view inside its parent; implementation is very
straightforward and I'm NOT calling supermethods here).
When I start dragging view #2, it sometimes triggers the swipe gesture recognizer. I can't really see the pattern, but this happens quite often.
Is there any way to suppress the touches processing while dragging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在视图 #2 上使用
UIPanGestureRecognizer
而不是直接处理触摸。在两个识别器的委托中,从gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
返回 NO。或者
在
UISwipeGestureRecognizer
的委托中,实现以下内容:Use a
UIPanGestureRecognizer
on view #2 instead of handling the touches directly. In the delegate for both recognizers, return NO fromgestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
.OR
In the
UISwipeGestureRecognizer
's delegate, implement this: