1
votes
UIView.animateWithDuration(1.0, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
                var angle = degreesToRadians(180)
                self.imageView.transform = CGAffineTransformMakeRotation(-angle)
            }, completion: { (value: Bool) in })

Why does the above transform rotate my imageView clockwise instead of counterclockwise? How can I change this behaviour to be the latter?

Edit:

UIView.animateWithDuration(1.0, delay: 1, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions.AllowUserInteraction, animations: {
                    var angle = degreesToRadians(180)
                    self.imageView.transform = CGAffineTransformMakeRotation(angle)
                }, completion: { (value: Bool) in })

causes the same behaviour to occur.

1
Did you try 179.999 or -179.999 :)Darko

1 Answers

1
votes

The animation is trying to rotate the view with a minimum amount of rotation. For example, given a desired rotation of 90 degrees, there are multiple ways to achieve it by rotating the view of

90 + 360 * i

degrees, i can be any integers, positive, negative, or zero. In this case, the animation will rotate the view by 90 degrees because that's the minimum amount of rotation that to achieved the specified desired rotation. Another example, even if you set desired rotation to the 450 (90 + 360), the animation will still only rotation 90 degrees.

In your case, 180 degrees is really the opposite side of the rotation. Therefore, there is no different between 180 and -180. If you want to force the view to rotation though a desired direction, you have to break the rotation down into multiple smaller ones. In this case, you can rotate the view by 90 degrees followed by another 90 degrees to guarantee the view to rotate the direction you want. Similarly, if you want it to rotate through the opposite direction, you can do two -90 degrees rotations one followed by another.