在uibutton内旋转png [英] rotate png inside uibutton
本文介绍了在uibutton内旋转png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在UINavigationBar的titleView
中有一个UIButton
.我想每次用户点击给定按钮时将向下的插入符号图像旋转180度.
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.
推荐答案
下面是使用Transforms的示例:-该代码适用于从UIView继承的所有元素
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)
}
这篇关于在uibutton内旋转png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文