Code for rotation took from here:
Swift Continuous Rotation Animation not so continuous
extension UIView {
func rotate360Degrees(duration: CFTimeInterval = 3) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(Double.pi * 2)
rotateAnimation.isRemovedOnCompletion = false
rotateAnimation.duration = duration
rotateAnimation.repeatCount=Float.infinity
self.layer.add(rotateAnimation, forKey: nil)
}
}
The problem is when I rotate this view around a pivot point this view is rotated around its center too and so square view becomes similar to rhombus. For example, if this view contains text then text is rotated too and becomes less readable.
How to solve this issue? I know if I had used CGAffineTransform
this problem would have been resolved somehow by multiplying various transformations. But CGAffineTransform
is broken on restarting animateWithDuration
. In the same time I don't know how and what to do with CABasicAnimation
at all.