Ios 使用3D触控精灵套件测量压力

Ios 使用3D触控精灵套件测量压力,ios,swift,sprite-kit,3dtouch,force-touch,Ios,Swift,Sprite Kit,3dtouch,Force Touch,在我的主应用程序中,我尝试使用3D触控激活子弹射击,但结果似乎非常不一致,并且它并不总是给出我的写入结果。当我使用这个代码时,我的iphone6s也崩溃了,这是我用于测试的代码 for touch in touches { let location = touch.locationInNode(self) var force = touch.force * 10 var maxForce = touch.maximumPossibleForc

在我的主应用程序中,我尝试使用3D触控激活子弹射击,但结果似乎非常不一致,并且它并不总是给出我的写入结果。当我使用这个代码时,我的iphone6s也崩溃了,这是我用于测试的代码

 for touch in touches {
        let location = touch.locationInNode(self)

        var force =  touch.force * 10
        var maxForce = touch.maximumPossibleForce

        print ("The force is")
        print (maxForce*4)
        print (force*10000000)

        if force != 0{


            myLabel.text = "Force"
            myLabel.fontSize = 45
            myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
            self.addChild(myLabel)
            myLabel.zPosition = 100000


        }

        else {

           myLabel.removeFromParent()
        }

我猜它会崩溃,因为您多次向父级添加标签(无论您调用什么函数,(
touchesbeated
touchesMoved
touchesend
)这些条件中只有一个始终为真,在
touchsbegind
touchsmoved
中,您的力始终为>0,在
touchsend
中,您的力应该为0。(我假设此代码就是您的
touchsmoved
)相反,在viewDidLoad代码中添加标签,并使用.hidden字段在移动时显示/隐藏标签。(确保在
上触摸Send
以隐藏标签)

我猜它会崩溃,因为您多次向父级添加标签(如果条件被破坏,无论您调用什么函数,(
touchsbegind
touchsmoved
touchsended
)这些条件中只有一个总是正确的,在
touchsbegind
touchsmoved
中,力总是>0,在
touchsend
中,力应该是0。(我假设这个代码就是你的
touchsmoved
)相反,在viewDidLoad代码中添加标签,并使用.hidden字段在移动中显示/隐藏标签。(确保在
触摸Send
上隐藏标签)

在哪个点崩溃?在哪个点崩溃??