问题描述
我已将UIScrollView设为第一响应者.我需要在其后面的视图上将触摸事件维护为-touchesEnded:withEvent:
方法.我尝试使用-nextResponder
方法,但失败了.我尝试将-touchesEnded:withEvent:
转发到其后面的视图,但失败了.
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.
如何使它正常工作?除非它是第一响应者或以其他方式获取事件,否则UIScrollView将无法工作.
How do I get this to work? The UIScrollView wont work unless it is the first responder or gets events some other way.
感谢您的帮助.可耻的Apple的文档和API在某些方面很糟糕.
Thank you for any help. Shame Apple's documentation and APIs are terrible in areas.
推荐答案
UIScrollView
以一种不寻常的方式处理触摸.从类参考中:
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.
滚动视图的超级视图不太可能看到触摸事件,因为其-hitTest:withEvent:
将返回滚动视图,因此触摸事件将发送到滚动视图,不需要将其转发到响应者链上回父级视图.
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.
第一响应者不影响触摸事件的传递,请参见 http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/EventsiPhoneOS/EventsiPhoneOS.html#//apple_ref/doc/uid/TP40009541-CH2-SW5
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
这篇关于touchesEnded:withEvent:来自UIScrollView第一响应器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!