【发布时间】:2020-11-28 04:45:33
【问题描述】:
我的应用有多个球,但一次只能移动。下面的代码显示,在 touchesBegan 我设置了在 touchesMoved 中使用的特定字段。在 touchesCancelled 和 touchesEnded 中,我重置了所有内容。
这是我的第一个 Swift 应用程序,但不是我的第一个程序,我知道用户喜欢尝试崩溃应用程序。因此,我用两根手指尽可能快地触摸多个球,最终,是的,在第一个球被设置为“移动”球之前,我在另一个球上运行了 touchesBegan。 是否有任何延迟属性可以让 iOS 在 touchesBegan 之间等待 0.3 秒?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
guard let touch = touches.first else { return }
let location = touch.location(in: self)
let touchedNodes = self.nodes(at: location)
for node in touchedNodes{
if let theNode = node as? MyBall {
if theNode.nodeType == .ball, theNode.isMoving == false,
(myGV.currentBall == nil) {
theNode.isMoving = true
theNode.zPosition += 1
myGV.currentBall = theNode
}
}
}
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?){
guard touches.first != nil else { return }
if let touch = touches.first, let node = myGV.currentBall, node.isMoving == true {
let touchLocation = touch.location(in: self)
node.position = touchLocation
node.isMoving = true
node.inSlot = false
}
}
【问题讨论】:
-
你想在 0.3 秒内禁用所有触摸吗?
-
@StefanOvomate 不,只是开始
标签: swift sprite-kit