触摸在iPhone中调用Canceled方法? [英] When touches Cancelled method get invoked in iPhone?

查看:122
本文介绍了触摸在iPhone中调用Canceled方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够理解,当用户触摸视图时,会触及Began和Ended。当用户在视图上滑动手时,触摸Moved方法被调用。但什么时候触及Canceled得到调用或者用户对该方法的调用是什么?

I am able to understand that when user just touches the view, touches Began and Ended called. When user swipes their hand on a view, touches Moved method gets called. But when does touches Cancelled get called or by what action on user this method gets called?

推荐答案

我想可能是最常见的原因for touchesCancelled被调用(因为iOS 3.2无论如何)跟随UIGestureRecognizer识别手势。如果您的视图附加了任何类型的手势识别器,那么提供touchesCancelled方法的自定义实现通常非常重要 - 请注意这包括使用手势识别器的现成视图,包括UIScrollView。

I think probably the most common reason for touchesCancelled being called (since iOS 3.2 anyway) is following the recognition of a gesture by a UIGestureRecognizer. If your view has any kind of gesture recognizer attached to it then it is often very important to provide a custom implementation of the touchesCancelled method - note this includes ready made views that use gesture recognizers, including UIScrollView.

默认情况下,手势识别器会在识别时取消触摸测试视图的触摸传递,但可以禁用此行为。这涉及将touchesCancelled消息发送到该视图,最有可能是在touchesBegan或touchesMoved消息之后。如果您的触摸处理代码依赖于touchesEnded方法中实现的代码,则可能永远不会触发此问题,并且可能会发生某种严重问题,因此需要在touchesCancelled中正确绑定任何松散的结尾。

By default, gesture recognizers cancel the delivery of touches to the hit-test view upon recognition, although this behaviour can be disabled. This involves sending the touchesCancelled message to that view, most likely following a touchesBegan or touchesMoved message. If your touch handling code is relying on code implemented in the touchesEnded method, it is possible this may never be fired and some kind of serious problem could occur, hence the need to properly tie up any loose ends in touchesCancelled.

手势识别器功能的细节显然比我在这里提到的要复杂得多 - 我完全建议阅读Apple的 Gesture Recognizers 文档。

The ins and outs of gesture recognizer functionality is obviously a bit more complex than I've mentioned here - I would thoroughly recommend reading Apple's Gesture Recognizers documentation.

另外,请查看手势上的 WWDC视频识别者(从2010年开始)。

Also, check out the WWDC videos on gesture recognizers (starting from 2010).

这篇关于触摸在iPhone中调用Canceled方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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