调用setCancelsTouchesInView时会发生什么? [英] What really happens when call setCancelsTouchesInView?

查看:179
本文介绍了调用setCancelsTouchesInView时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道当我调用setCancelsTouchesInView时会发生什么。官方文档 http: //developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

Wondering what really happens when i call setCancelsTouchesInView. It is not covered in the official document http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

谢谢

推荐答案

ACB引用 UIGestureRecognizer 参考。为了使它更具体一些,假设你有一个带有平移手势识别器的视图,你在视图控制器中有这些方法:

ACB quoted the UIGestureRecognizer reference. To make it a little more concrete, suppose you have a view with a pan gesture recognizer attached, and you have these methods in your view controller:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesBegan");
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesMoved");
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesEnded");
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"touchesCancelled");
}

- (IBAction)panGestureRecognizerDidUpdate:(UIPanGestureRecognizer *)sender {
    NSLog(@"panGesture");
}

当然,平移手势识别器配置为发送 panGestureRecognizerDidUpdate:消息。

And of course the pan gesture recognizer is configured to send the panGestureRecognizerDidUpdate: message.

现在假设您触摸视图,移动手指足以识别平移手势,然后抬起你的手指该应用程序打印什么?

Now suppose you touch the view, move your finger enough for the pan gesture to be recognized, and then lift your finger. What does the app print?

如果手势识别器 cancelsTouchesInView 设置为 YES 该应用程序将记录以下消息:

If the gesture recognizer has cancelsTouchesInView set to YES, the app will log these messages:

touchesBegan
touchesMoved
touchesCancelled
panGesture
panGesture
(etc.)

取消前你可能会获得多个 touchesMoved

You might get more than one touchesMoved before the cancel.

所以,如果设置 cancelsTouchesInView YES (默认值),系统会在从手势识别器发送第一条消息之前取消触摸,然后你不再为该触摸获取与触摸相关的消息。

So, if you set cancelsTouchesInView to YES (the default), the system will cancel the touch before it sends the first message from the gesture recognizer, and you won't get any more touch-related messages for that touch.

如果手势识别器具有 cancelsTouchesInView 设置为该应用将记录以下消息:

If the gesture recognizer has cancelsTouchesInView set to NO, the app will log these messages:

touchesBegan
touchesMoved
panGesture
touchesMoved
panGesture
touchesMoved
panGesture
(etc.)
panGesture
touchesEnded

所以,如果你设置 cancelsTouchesInView ,系统将继续发送手势触摸的触摸相关消息,与手势识别器的消息交错。触摸将正常结束而不是被取消(除非系统因某些其他原因取消触摸,例如在触摸期间按下主页按钮)。

So, if you set cancelsTouchesInView to NO, the system will continue sending touch-related messages for the gesture touch, interleaved with the gesture recognizer's messages. The touch will end normally instead of being cancelled (unless the system cancels the touch for some other reason, like the home button being pressed during the touch).

这篇关于调用setCancelsTouchesInView时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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