TouchesEnded:withEvent:来自 UIScrollView 第一响应者
我已将 UIScrollView 设置为第一响应者。我需要在其后面的视图上维护 -touchesEnded:withEvent:
方法的触摸事件。我尝试使用 -nextResponder
方法但失败了。我尝试将 -touchesEnded:withEvent:
转发到其后面的视图,但失败了。
我该如何让它发挥作用? UIScrollView 不会工作,除非它是第一响应者或以其他方式获取事件。
感谢您的帮助。遗憾的是苹果的文档和 API 在某些方面很糟糕。
I've made a UIScrollView the first responder. I need to maintain touch events to a -touchesEnded:withEvent:
method on a view behind it. I've tried using the -nextResponder
method and that failed. I've tried forwarding -touchesEnded:withEvent:
to the view behind it and that fails.
How do I get this to work? The UIScrollView wont work unless it is the first responder or gets events some other way.
Thank you for any help. Shame Apple's documentation and APIs are terrible in areas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UIScrollView
以一种稍微不寻常的方式处理触摸。来自类参考:滚动视图的内容视图中的子视图最终将接收对滚动视图的非滚动触摸。
滚动视图的超级视图不太可能看到触摸事件,因为它的
-hitTest:withEvent:
将返回滚动视图,因此触摸事件将被发送到滚动视图,而无需将它们转发回去到父视图的响应者链。第一响应者不会影响触摸事件的传递,请参阅 http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/EventsiPhoneOS/EventsiPhoneOS.html#//apple_ref/doc/uid /TP40009541-CH2-SW5
UIScrollView
handles touches in a slightly unusual way. From the class reference:A subview within the scroll view's content view will eventually receive non-scrolling touches to the scroll view.
A superview of a scroll view is unlikely to see touch events as its
-hitTest:withEvent:
will return the scroll view so touch events will be sent to the scroll view which is not required to forward them back up the responder chain to the parent view.First responder does not influence the delivery of touch events, see http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/EventsiPhoneOS/EventsiPhoneOS.html#//apple_ref/doc/uid/TP40009541-CH2-SW5