UIPanGestureRecognizer表现异常

下面的代码用于在我的手指平移精灵时更改精灵的颜色。它可以工作,但精灵仅在手势结束后才更改颜色。例如,我首先平移精灵并绘制形状-平移时没有任何变化-然后我抬起手指,精灵会改变颜色。

打印语句正在报告正确的精灵名称,并且所有打印语句都已被触发...但是精灵颜色的更改要到最后才开始。

这让我感到困惑,所以我希望有人能够解释。

   @objc func drawingpan(_ recognizer: UIPanGestureRecognizer) {

    recognizer.minimumNumberOfTouches = 1
    if recognizer.state == .began {

        print("drawingbegan")
        var touchLocation = recognizer.location(in: recognizer.view)
        var touchLocation2 = self.convertPoint(fromView: touchLocation)
        let nn = nodes(at: touchLocation2)
        if nn.count > 0 {
            if let dotSpritetapped = nn.first! as? SKSpriteNode {
                print("touchebeganpan",dotSpritetapped.name)
                for spritesquare in MyVariables.allsprites {
                    if dotSpritetapped.name == spritesquare.name {
                        print("changecolorpan",dotSpritetapped.name)
                        spritesquare.color = UIColor.red
                    }
                }}
        }
    }

} else if recognizer.state == .changed {
print("touchechangedx")

var touchLocation = recognizer.location(in: recognizer.view)
var touchLocation2 = self.convertPoint(fromView: touchLocation)
let nn = nodes(at: touchLocation2)
if nn.count > 0 {
    if let dotSpritetapped = nn.first! as? SKSpriteNode {
        for spritesquare in MyVariables.allsprites {
            if dotSpritetapped.name == spritesquare.name {
                print("namesmatch",dotSpritetapped.name)
                spritesquare.color = UIColor.red
}
}}
}
}


    } else if recognizer.state == .ended {
    //recognizer.cancelsTouchesInView = false
    }}
afang2468 回答:UIPanGestureRecognizer表现异常

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2815828.html

大家都在问