1

CGAffineTransformMakeRotation() generates on iOS 7 a weird bug when trying to rotate an object (label, button, etc.) to an angle different than 90, 180, 360, etc.

From iOS 8 and onwards the bug is gone.

The fix is in the answer below.

Lawrence413
  • 1,976
  • 1
  • 14
  • 28

1 Answers1

0

The fix to this bug is to apply a CABasicAnimation on the layer, not a CGAffineTransformMakeRotationon the view of the button.

For some reason when you apply it on the view, it messes with the frame and AutoLayout. More info here.

Here's how to implement this fix:

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")
Community
  • 1
  • 1
Lawrence413
  • 1,976
  • 1
  • 14
  • 28