视图变换旋转在iOS中消除图像渲染效果
我创建了一个视图变换旋转在iOS中消除图像渲染效果,ios,swift,animation,view,Ios,Swift,Animation,View,我创建了一个UIButton,如下所示(带有阴影属性的圆形按钮,没有什么特别的): 其目的是在单击时看起来像一个添加按钮,它旋转形成一个十字按钮 func handleClick() { button.isSelected = !newPostButton.isSelected let rotationDirection: CGFloat = button.isSelected ? 1: -1 UIView.animate(withDuration: 0.5) {
UIButton
,如下所示(带有阴影属性的圆形按钮,没有什么特别的):
其目的是在单击时看起来像一个添加按钮,它旋转形成一个十字按钮
func handleClick() {
button.isSelected = !newPostButton.isSelected
let rotationDirection: CGFloat = button.isSelected ? 1: -1
UIView.animate(withDuration: 0.5) {
self.button.transform = self.button.transform.rotated(by: (rotationDirection * .pi/4))
}
}
我遇到的问题是,当动画发生旋转时,旋转工作正常,但为按钮.withRendering:
提供的图像无效,如下所示:
有办法吗?(请不要使用代码库)我在网上搜索过,但没有一个出现类似问题。您可以将按钮类型设置为
.custom
而不是.system
。这将解决您的问题。谢谢,您节省了很多时间。
func handleClick() {
button.isSelected = !newPostButton.isSelected
let rotationDirection: CGFloat = button.isSelected ? 1: -1
UIView.animate(withDuration: 0.5) {
self.button.transform = self.button.transform.rotated(by: (rotationDirection * .pi/4))
}
}