UIView.animate(withDuration:2.0, animations: {
self.imageView.transform = CGAffineTransform(rotationAngle: (270 * CGFloat(2 * Double.pi)) / 360.0)
})
This is animating anti clockwise i want the animation clockwise.
To rotate by 270 degrees clockwise...
UIView.animate(withDuration:2.0, animations: {
self.sampleView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
self.sampleView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi * 3 / 2))
})
Core Animation will always take the shortest route to make the rotation work. So, if your object is straight and you rotate to 90 degrees (radians: pi/2), it will rotate clockwise. If your object is straight and you rotate to 270 degrees (radians: pi + pi/2 = 3pi/2) it will rotate counter-clockwise because it's the smallest possible animation.
So we first need to rotate by pi radians (from 0 -> pi, 0 -> 180) then rotate by another pi/2 radians (pi -> 3pi/2, 180 -> 270) to perform the full rotation.
Notes :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With