CGAffineTransformMakeRotation()
会在iOS 7上生成一个奇怪的错误。
从iOS 8开始,错误消失了。
修复程序在下面的答案中。
答案 0 :(得分:0)
此错误的修复方法是在图层上应用CABasicAnimation
,而不是在按钮的视图上应用CGAffineTransformMakeRotation
。
出于某种原因,当您在视图上应用它时,它会与框架和AutoLayout混淆。更多信息here。
以下是如何实施此修复程序:
let animation = CABasicAnimation(keyPath: "transform.rotation")
animation.autoreverses = false
animation.duration = 0.3
animation.fromValue = 0
animation.fillMode = kCAFillModeForwards
animation.removedOnCompletion = false
animation.toValue = 3.14/4 // 45 degrees
self.myButton.layer.addAnimation(animation, forKey: "45rotation")