0
图像渲染效果
我创建了一个UIButton
如下(有阴影属性没有什么太花哨圆形按钮):查看变换旋转抵消iOS中
let button = UIButton(type: .system)
button.backgroundColor = UIColor(hexString: "4267B2")
button.tintColor = .white
button.setImage(#imageLiteral(resourceName: "add").withRenderingMode(.alwaysTemplate), for: .normal)
button.addTarget(self, action: #selector(handleClick), for: .touchUpInside)
button.translatesAutoresizingMaskIntoConstraints = false
button.layer.cornerRadius = 32
button.layer.shadowColor = UIColor.darkGray.cgColor
button.layer.shadowRadius = 6
button.layer.shadowOpacity = 0.6
button.layer.shadowOffset = CGSize.zero
目的是为了看起来就像上单击它旋转的添加按钮形成一个十字按钮。
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:
图像被废止,如下图所示:
有没有解决? (请不要使用代码库)我通过网络搜索,但没有发现类似的问题。
谢谢,你节省了很多时间。 –
不客气:) –