14

Rotate a button to make a similar animation when clicked?

image
(source: cloudfront.net)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Omar Shiltawi
  • 151
  • 1
  • 1
  • 5

2 Answers2

35

Swift 3:

UIView.animate(withDuration: 0.25, animations: {
    myButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
})

More information on rotation in Swift: Swift: How can you rotate text for UIButton and UILabel?

Caleb
  • 5,548
  • 3
  • 25
  • 32
4

You can use a regular rotation on the button:

[myButton setTransform:CGAffineTransformMakeRotation(M_PI_4)];

that would rotat + a 45degrees and make it an X :)

if you want to animate as well try

[UIView animateWithDuration:.5 animations:^{
        myButton.transform = CGAffineTransformMakeRotation(M_PI_4);
    }];
dorian
  • 847
  • 5
  • 11