touchesEnded:withEvent: from UIScrollView First Responder

淺唱寂寞╮ 提交于 2019-12-11 23:51:39

问题


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:


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...



来源:https://stackoverflow.com/questions/4597217/touchesendedwithevent-from-uiscrollview-first-responder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!