TouchesEnded:withEvent:来自 UIScrollView 第一响应者

发布于 2024-10-10 00:49:40 字数 291 浏览 8 评论 0原文

我已将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒带 2024-10-17 00:49:40

UIScrollView 以一种稍微不寻常的方式处理触摸。来自类参考:

因为滚动视图没有滚动条,所以它必须知道触摸信号是否表示滚动意图或跟踪内容中的子视图的意图。为了做出此确定,它通过启动计时器来临时拦截触地事件,并在计时器启动之前查看触摸手指是否进行任何移动。如果计时器在位置没有显着变化的情况下触发,则滚动视图会将跟踪事件发送到内容视图的触摸子视图。如果用户在计时器结束之前将手指拖动得足够远,则滚动视图将取消子视图中的任何跟踪并自行执行滚动...

滚动视图的内容视图中的子视图最终将接收对滚动视图的非滚动触摸。

滚动视图的超级视图不太可能看到触摸事件,因为它的 -hitTest:withEvent: 将返回滚动视图,因此触摸事件将被发送到滚动视图,而无需将它们转发回去到父视图的响应者链。

第一响应者不会影响触摸事件的传递,请参阅 http://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/EventsiPhoneOS/EventsiPhoneOS.html#//apple_ref/doc/uid /TP40009541-CH2-SW5

第一响应者是应用程序中的响应者对象(通常是 UIView 对象),它被指定为除触摸事件之外的事件的第一个接收者...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文