touchesEnded:withEvent:来自UIScrollView第一响应器 [英] touchesEnded:withEvent: from UIScrollView First Responder

查看:114
本文介绍了touchesEnded:withEvent:来自UIScrollView第一响应器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将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:

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

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.

滚动视图的超级视图不太可能看到触摸事件,因为其-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.

第一响应者不影响触摸事件的传递,请参见

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

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

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

这篇关于touchesEnded:withEvent:来自UIScrollView第一响应器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆