当子视图被触摸时,UIRecognizers 不应该触发吗?
我的 iPad 应用程序中的视图的行为就好像当用户在该视图中启动此类手势时,它们会阻止其超级视图的手势识别器触发。
这是预期的吗? 我怎样才能消除这种屏蔽行为? 调试手势识别器有哪些好的做法?
更详细地说:
我的应用程序的主要“画布”视图允许用户通过“长双击”向其添加形状。我在主视图中附加了一个用于此类手势的手势识别器。这非常有效:主视图被调用,并通过向主视图添加形状来做出反应。
形状作为主视图的子视图实现。当用户在主视图中长按两次时,我的代码会实例化一个形状子视图,并将其添加到主视图中。可以使用长按识别器来移动形状视图。因此,我还为每个形状视图附加了一个用于长按的手势识别器。这非常有效:形状视图被调用并允许用户在画布中移动它。
但是,当用户在形状视图中长按两次时,不会发生任何情况:不会调用形状视图,这是预期的,因为它没有用于长按两次的手势识别器。但主视图也没有被调用。我原以为,由于形状视图无法识别该手势,因此它将在响应者链中向上传播到主视图。但这并没有发生。
我的目的是让用户向主视图添加重叠的形状,这样长按两次形状也会向主视图添加一个新形状。
我可能错过了什么?
当然,我可以向形状视图添加一个长双击识别器,然后从那里将手势转发到主视图,或者以类似于我在主视图中所做的方式直接处理手势。
但这听起来很浪费,更重要的是,我想了解这种行为。
感谢您的任何建议。
Views in my iPad app behave as if they prevent their superview's gesture recognizers from firing when the user initiates such gesture in that view.
Is this expected?
How can I remove that shielding behavior?
What are good practices to debug gesture recognizers?
In more details:
The main "canvas" view of my application, lets the user adds shapes to it with a "long double tap". I attached a gesture recognizer for such gestures to the main view. That works very well: the main view gets called, and reacts by adding a shape to the main view.
Shapes are implemented as subviews of the main view. When the user long-double-taps in the main view, my code instanciate a shape subview, and adds it to the main view. Shape views can be moved around with a long-single-tap recognizer. So I also attach a gesture recognizer for long-single-taps to every shape view. That works very well: the shape view gets called and lets the user move it in the canvas.
However, when the user long-double-taps in a shape view, nothing happens: the shape view is not called, which is expected since it doesn't have a gesture recognizer for long-double-taps. But the main view is not called either. I had thought that since the gesture was not recognized by the shape view, then it would be propagated up in the responder chain to the main view. But this doesn't happen.
My intent is to let the user add overlapping shapes to the main view, so that a long-double-tap on a shape would also add a new shape to the main view.
What could I have missed?
I can of course add a long-double-tap recognizer to shape views, and from there, either forward the gesture to the main view or handle the gesture directly in a way similar to what I do in the main view.
But this sounds wasteful, and more importantly, I'd like to understand the behavior.
Thanks for any suggestion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,它应该开箱即用地传递消息。
为了确保两个
gestureRecognizers
都不会被触发,您需要执行以下操作:更新
这里只是自由样式,但如果您想将手势限制为一个视图,您可以尝试使用手势委托(仅当触摸的视图是
self.view
时才会响应)在您的控制器中执行以下操作:
NB 我还没有测试过这个,但我会在我测试时更新稍后测试一下。
It should as far as I can see pass the message along out of the box.
To ensure both
gestureRecognizers
are not fired you need to do something like:Update
Just free styling here but if you want to limit the gesture to one view you could try playing with the gesture delegate (this will only respond if the touched view is
self.view
)In your controller do something like:
NB I haven't tested this but I will update when I test it later.