iOS Swift: CGAffineTransform Make Rotation 在旋转之间重置

iOS Swift: CGAffineTransformMakeRotation resets between roations

我正在使用 UIRotationGestureRecognizer 来旋转视图。当我释放视图然后重新开始时,它会捕捉到 Identity 旋转,然后再返回旋转。我正在尝试弄清楚如何让它顺利地继续下一次轮换活动。我能在这里找到的唯一问题是几年前没有得到解答。

如果有人更愿意以这种方式回应,我可以从 Obj-C 移植。

我确定我遗漏了一些明显的东西,但你是我唯一的希望,Obi Wan Whosebug。

func rotateToRotate(rotationRecognizer: UIRotationGestureRecognizer) {
    let rotation = rotationRecognizer.rotation
    if rotationRecognizer.state == UIGestureRecognizerState.Began {
        self.view.transform = CGAffineTransformMakeRotation(0 + self.lastRotation)
        return
    }

    if rotationRecognizer.state == UIGestureRecognizerState.Ended {
        self.view.transform = CGAffineTransformMakeRotation(rotation)
        self.lastRotation = rotation
        return
    }

    self.view.transform = CGAffineTransformMakeRotation(rotation)
}

原来是自动完成让我误入歧途。 CGAffineTransformMakeRotation CGAffineTransformRotate 不同。前者不改变CGAffineTransformIdentity,后者改变

更正后的代码:

func rotateToRotate(rotationRecognizer: UIRotationGestureRecognizer) {
    let rotation = rotationRecognizer.rotation
    self.view.transform = CGAffineTransformRotate(self.view.transform, rotation)
    rotationRecognizer.rotation = 0.0
}