正如标题所说,我怎样才能使旋转手势只应用一次?例如,我希望一个正方形在旋转手势被重新定位后旋转90度。这是我目前正在使用的代码。它几乎可以工作,因为它应该旋转一次时旋转两次或更多次。我的代码有什么问题或者我该如何解决这个问题?
if (rotationGestureRegonizer.rotation.toDegree >= 30 && !neveragain) {
rot += Float(M_PI/2.5)
redArrow.position = CGPointMake(shapeLayer.position.x+CGFloat(sinf(rot)*70),shapeLayer.position.y+CGFloat(cosf(rot)*70))
var transform = CATransform3DIdentity;
transform = CATransform3DRotate(shapeLayer.transform, CGFloat(M_PI/2.5), 0.0, 0.0, 1.0);
var transform2 = CATransform3DIdentity;
transform2 = CATransform3DRotate(redArrow.transform, CGFloat(M_PI/2.5), 0.0, 0.0, -1.0);
shapeLayer.transform = transform
redArrow.transform = transform2
neveragain = true
}
override func touchesEnded(touches: NSSet!, withEvent event: UIEvent!) {
println("touch up")
neveragain = false
}
答案 0 :(得分:1)
在手势回调函数中,在gestureRecognizer.state == UIGestureRecognizerStateBegan
为真时运行代码