14

Rotate a button to make a similar animation when clicked?

image
(source: cloudfront.net)

Glorfindel
  • 20,880
  • 13
  • 75
  • 99
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,402
  • 2
  • 23
  • 32
3

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
  • 829
  • 5
  • 11