我最近更新了iOS10和Swift 3,并且知道,每当我在iOS10设备上运行我的应用程序(在我的例子中是iPhone6s)时,touchesBegan函数就会出现随机延迟。有时,这会伴随以下错误消息:
“手势:下一次触摸前未能收到系统手势状态通知”
有趣的是,运行iPhone5s的旧iOS9不会重现这个问题。
发布于 2016-09-14 14:28:41
通常,iOS上奇怪的UI延迟与线程有关。iOS和Mac上与UI相关的方法都只能从主线程调用。由于API正变得高度异步,许多方法都采用块回调,因此很容易意外地从后台线程执行与UI相关的操作。
确保任何与UI相关的活动,无论是更新图像、文本字段、重新加载表视图等等,都是从主线程执行的。如果在块中执行UI内容,则可以将UI部件包装在dispatch_async(dispatch_get_main_queue(),.)中。
我的经验是,一个不经意的背景线程调用这些方法之一可能会产生“毒害井”的效果,导致后续的怪事,例如你看到的延迟触摸事件。
发布于 2016-09-19 12:56:39
我有同样的问题,我模拟触摸和保持驾驶一辆车左右。这就是帮我修的东西。
从以下位置更改:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if let touch = touches.first {
let location = touch.location(in: self)
let node: SKNode = atPoint(location)
if node == self.player1CarRight {
self.player1CarRotateRightTouching = true
}
}
}To:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first! as UITouch
let touchLocation = touch.location(in: self)
if player1CarRight.contains(touchLocation) {
self.player1CarRotateRightTouching = true;
}
}touchesEnded中的相同更改:
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch:UITouch = touches.first! as UITouch
let touchLocation = touch.location(in: self)
if player1CarRight.contains(touchLocation) {
self.player1CarRotateRightTouching = false
}
}发布于 2016-09-20 21:51:28
我今天遇到了这种行为,但可能是因为另一个原因。我的场景包括在实现touchesBegan的视图的超级视图上拥有一个touchesBegan。由于UITapGestureRecognizer正在识别tap,而且由于tap识别器上的cancelsTouchesInView的默认设置是肯定的,所以一旦识别器识别了触摸,视图就不会得到任何触摸回调。但是,如果我触摸和保持,UITapGestureRecognizer无法识别触摸,然后视图将得到回调。这导致了对touchesBegan的延迟调用。
我还注意到,作为这项调查的一部分,UIButtons在这里得到了特殊待遇。如果UITapGestureRecognizer正在发挥作用,它将不会考虑接触UIButtons。
https://stackoverflow.com/questions/39492709
复制相似问题