I have an UIImageView and I would like it so that when I call a function, the image goes from flat(the normal state), to a tilting to the right rotation(say maybe a 20 degree rotation), then back to it's flat(normal) state.
This is what I currently have, but I can't get the desired outcome.
extension UIView {
func rotate(duration: CFTimeInterval = 2) {
let rotateAnimation = CABasicAnimation(keyPath: "transform.rotation")
rotateAnimation.fromValue = 0.0
rotateAnimation.toValue = CGFloat(20)
rotateAnimation.isRemovedOnCompletion = true
rotateAnimation.duration = duration
rotateAnimation.repeatCount=Float.infinity
self.layer.add(rotateAnimation, forKey: nil)
}
}
UIImageView.rotate()
I tried Creating the above Animation and my tried code Is here
Required Declarations
Timer Functions
Timer Handler
Button Action
ScreenShots
First :
Second:
Running Output