开发者

Why is the UIEvent a different object in touchesBegan and touchesMoved?

In the example project aurioTouch application delegate the code indicates (and I've read elsewhere) that the touch event object passed to touchesBegan, touchesMoved, and touchesEnded will be the same object while it is still a single set of user actions,开发者_Python百科 such as touching and moving a finger. When I override UIScrollView and implement these methods, the events that I get back are different objects. What am I missing here?


The UITouch objects will be the same, but they are packaged in a new event.


You are right that the UIEvent is reused when delivering touch events for one gesture. From the docs:

A UIEvent object representing a touch event is persistent throughout a multi-touch sequence; UIKit reuses the same UIEvent instance for every event delivered to the application. You should never retain an event object or any object returned from an event object. If you need to keep information from an event around from one phase to another, you should copy that information from the UITouch or UIEvent object.

I presume the difference in behavior for your case results from the special event handling done by UIScrollView. Scroll views delay event delivery because they need to detect a scrolling intent by the user (swipe gestures). So they have to have a way of keeping UIEvents around—probably copying them to make sure they retain their original state. This might be the reason you see different objects.

Note that all of the above is only guessing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜