简体   繁体   English

在uibutton内旋转png

[英]rotate png inside uibutton

I have a UIButton inside a titleView of a UINavigationBar. 我在UINavigationBar的titleView内有一个UIButton I want to rotate a downwards caret image 180 degrees every time the user taps a given button. 我想每次用户点击给定按钮时将向下的插入符号图像旋转180度。

在此处输入图片说明

Here's an example of how can you do it using Transforms:- The code works with all the elements that inherits from UIView 这是一个如何使用Transforms的示例:-该代码适用于从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)

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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