UIGestureRecognizer 不消耗点击
我有一个 UIViewController,我正在向主视图添加子视图。主视图有一个 UIGestureRecogniser,每个子视图也有一个 UIGestureRecognizer。在界面生成器中,我已经在属性检查器中检查了视图中的取消,因此我希望子视图上的点击只会在子视图处理程序中触发我的gestureRecognizerShouldBegin,但它们也会触发附加到它们所在视图的处理程序。
有谁知道为什么会出现这种情况?
我想我可以保留附加到每个子视图的 GestureRecogniser 特定实例的句柄,并比较所触发的事件是否来自正确的识别器,但这似乎不是正确的解决方案。任何帮助都会非常有用。
编辑:第二个解决方案甚至不起作用,似乎每个符合当前手势的 UIGestureRecogniser 都被解雇了!
编辑: 我想出的最佳解决方案是,
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ if([view isEqual:[触摸视图]] && self.editing) 返回是;
返回NO; ( BOOL
根本不接收触摸
I have a UIViewController and I am adding subviews to the main view. The main view has a UIGestureRecogniser and each subview also has a UIGestureRecognizer. In interface builder I have checked canceled in view in the attributes inspector so I would expect taps on the subviews to only fire my gestureRecognizerShouldBegin in the subview handler but they are also firing the handler attached to the view they are place on.
Does anyone have any idea why this might be the case?
I guess I could keep a handle to the particular instance of the GestureRecogniser attached to each subview and compare if the event being fired has come from the correct recogniser but this does not seem like the correct solution. Any help would be much appricated.
Edit: This second solution doesn't even work seems like every UIGestureRecogniser conforming to the current gesture is being fired!
Edit:
The best solution I have come up with is,
(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if([view isEqual:[touch view]] && self.editing)
return YES;return NO;
}
I would like the Gesture not to receive the touch at all though
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论