gpt4 book ai didi

iphone - 调用 set CancelsTouchesInView 时到底发生了什么?

转载 作者:技术小花猫 更新时间:2023-10-29 11:10:14 34 4
gpt4 key购买 nike

想知道当我调用 set CancelsTouchesInView 时到底发生了什么。官方文档中没有涉及http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizer_Class/Reference/Reference.html

谢谢

最佳答案

ACB 引用了 UIGestureRecognizer 引用。为了使它更具体一点,假设您有一个附加了平移手势识别器的 View ,并且您的 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: 消息。

现在假设您触摸 View ,将手指移动到足以识别平移手势的程度,然后抬起手指。该应用打印什么?

如果手势识别器将 cancelsTouchesInView 设置为 YES应用将记录这些消息:

touchesBegan
touchesMoved
touchesCancelled
panGesture
panGesture
(etc.)

在取消之前,您可能会得到不止一个 touchesMoved

因此,如果您将 cancelsTouchesInView 设置为 YES(默认值),系统将在从手势识别器发送第一条消息之前取消触摸,您就赢了' 为该触摸获取更多与触摸相关的消息。

如果手势识别器将 cancelsTouchesInView 设置为 NO 应用将记录这些消息:

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

因此,如果您将 cancelsTouchesInView 设置为 NO,系统将继续为手势触摸发送与触摸相关的消息,并与手势识别器的消息交织在一起。触摸将正常结束而不是被取消(除非系统出于其他原因取消触摸,例如触摸期间按下主页按钮)。

关于iphone - 调用 set CancelsTouchesInView 时到底发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13042632/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com