为什么 UIEvent 在touchesBegan和touchesMoved中是不同的对象?
在示例项目中 aurioTouch application delegate 代码表明(我在其他地方读过)传递给touchesBegan、touchesMoved 和touchesEnded 的触摸事件对象将是同一个对象,但它仍然是一组用户操作,例如触摸和移动手指。当我重写 UIScrollView 并实现这些方法时,我返回的事件是不同的对象。我在这里缺少什么?
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, 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
UITouch
对象将是相同的,但它们被打包在一个新事件中。The
UITouch
objects will be the same, but they are packaged in a new event.您是对的,在为一个手势传递触摸事件时会重用
UIEvent
。来自 文档:我认为您的情况的行为差异是由
UIScrollView
完成的特殊事件处理造成的。滚动视图延迟事件传递,因为它们需要检测用户的滚动意图(滑动手势)。因此,他们必须有一种方法来保留 UIEvents——可能是复制它们以确保它们保留其原始状态。这可能是您看到不同物体的原因。请注意,以上所有内容都只是猜测。
You are right that the
UIEvent
is reused when delivering touch events for one gesture. From the docs: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.