7

I would like apply a 3D rotation on a view (in particular to a UILabel) in iPhone. What's the simplest way to do this?

A code example will be much appreciated.

hpique
  • 119,096
  • 131
  • 338
  • 476

3 Answers3

13

For 2D rotation use:

//rotate label in 45 degrees
label.transform = CGAffineTransformMakeRotation( M_PI/4 );

For 3D transformations see this thread:

CATransform3D _3Dt = CATransform3DMakeRotation(radians(90.0f), 1.0, 0.0, 0.0);
Community
  • 1
  • 1
sashaeve
  • 9,387
  • 10
  • 48
  • 61
9
// flipping view along axis
// this will rotate view in 3D along any axis 

[UIView beginAnimations:nil context:nil];
CATransform3D _3Dt = CATransform3DRotate(self.layer.transform, 3.14, 1.0, 0.0,0.0);
[UIView setAnimationRepeatCount:100];
[UIView setAnimationDuration:0.08];
self.layer.transform=_3Dt;
[UIView commitAnimations];
Ankit Bhardwaj
  • 221
  • 2
  • 9
2

Swft 3 example

let rotationTransform = CATransform3DRotate(myView.layer.transform, CGFloat.pi, 1, 0, 0)

UIView.animate(withDuration: 0.5) {
    self.myView.layer.transform = rotationTransform
}
Evgeny Karev
  • 605
  • 6
  • 13