CGAffineTransformMakeRotation iOS 7框架更改错误修复

时间:2016-07-19 15:41:50

标签: swift ios7

在尝试将对象(标签,按钮等)旋转到不同于90,180,360等的角度时,

CGAffineTransformMakeRotation()会在iOS 7上生成一个奇怪的错误。

从iOS 8开始,错误消失了。

修复程序在下面的答案中。

1 个答案:

答案 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")