ios - SKaction 阻止了 touchesBegan 事件

标签 ios multithreading swift skaction

我有一个不同正方形的网格。当用户单击正方形时,该正方形会翻转。但在翻转期间,touchesBegan 事件不起作用。

此代码在点击方 block 后执行:

 func flipTile(node : RectSprite){
    let flip = SKAction.scaleXTo(-1, duration: 0.5)
    let flip2 = SKAction.scaleXTo(-1, duration: 0.2)

    node.setScale(1.0)
    var key : String = Array(CircleColor.colors.keys.array)[10]
    var changeColor = SKAction.runBlock( { node.texture = SKTexture(imageNamed:"white")})
    var removeCombinaison = SKAction.runBlock( {
        self.combination.last?.removeFromParent()
        self.combination.removeLast()
        self.updateGrid()

    })

    var action = SKAction.sequence([flip, changeColor])
    var action2 = SKAction.sequence([flip2, removeCombinaison] )

    node.imageName = "white"
    node.name = "square"
    node.runAction(action)
    self.combination.last?.runAction(action2)
}

但是,如果我在下一个方 block 中快速单击,则事件触摸不起作用。也许我需要在新线程中执行这段代码。

最佳答案

您可以尝试使用以下方法检查触摸位置(我认为这甚至可以在翻转动画期间使用):

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    /* Called when a touch begins */

    for touch in (touches as! Set<UITouch>) {
        let location = touch.locationInNode(self)

        if yourNode.containsPoint(location) {
        /* called whenever the square is touched */
        } else {
        /* called when some other location on the screen is touched */
        }
    }
}

关于ios - SKaction 阻止了 touchesBegan 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32105115/

相关文章:

ios - 使用搜索在 App 内启动 iTunes Store

json - 无法获取路径 Swift Playground 错误的沙箱扩展

ios - 在 XCode 中使用 XMPPFramework 时如何查看 XML?

ios - 有没有办法获取 iOS 应用程序的所有 View Controller 的类名?

ios - 全刷UITableViewCell删除UITableView iOS 8

c# - 如何在 WPF 中处理长时间运行的 "thread"?

c# - Redis Pub/Sub ServiceStack,取消线程

java - Spark 如何实现任务间的内存公平?

swift - 如何在标记中显示图表点 (x, y) 以外的数据?

ios - 在 Swift 中将变量传递回父级