简体   繁体   中英

rotate png inside uibutton

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 button.

在此处输入图片说明

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)

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM