touchesEnded:withEvent: from UIScrollView First Re

2019-09-01 06:50发布

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.

1条回答
ら.Afraid
2楼-- · 2019-09-01 07:32

UIScrollView handles touches in a slightly unusual way. From the class reference:

Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself...

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

The first responder is the responder object in an application (usually a UIView object) that is designated to be the first recipient of events other than touch events...

查看更多
登录 后发表回答