处理触摸
我有一个带有多个子视图的 UIView 子类,我想在类中处理这些事件:
- touchesBegan:withEvent:
- touchesMoved:withEvent:
- touchesEnded:withEvent:
但我也希望在子视图中调用这些事件。我怎样才能做到这一点?
(我已经尝试过 hitTest,但我只收到 TouchBegan 事件,并且该方法没有发送任何触摸)
I have a UIView subclass with several subviews and I want to handle these events in the class:
- touchesBegan:withEvent:
- touchesMoved:withEvent:
- touchesEnded:withEvent:
but I also want these event to be called at the subviews. How can I accomplish that?
(I have already tried with hitTest, but I only get the touchesBegan event and no touches are send with the method)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法通过在主窗口中重写以下方法来解决这个问题:
来检查它是否是正确的事件
我还通过对 UITouchPhaseMoved 和 UITouchPhaseEnded 执行相同的操作 ,执行我的自定义代码,然后发送
[super sendEvent:anEvent];
I have managed to solve it by overriding the following method at the main window:
I also check if it is the right event with through
I do the same for
UITouchPhaseMoved
andUITouchPhaseEnded
, execute my custom code and then send[super sendEvent:anEvent];