I have a UIButton
inside a titleView
of a UINavigationBar. I want to rotate a downwards caret image 180 degrees every time the user taps a given b
Here's an example of how can you do it using Transforms:- The code works with all the elements that inherits from UIView
UIView.animate(withDuration: 0.5) {
self.yourButton.imageView?.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
}
To set it back to original position:-
UIView.animate(withDuration: 0.5) {
self.yourButton.imageView?.transform = .identity)
}