Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate UIView in Cocoa Touch

I have seen other people who have had this question, but most of the responses aren't working on the latest 3.0 build of iPhone OS. Anyway, I'm wondering how I can programatically rotate a UIView without any input from the accelerometer. The code I have found so far:

CGAffineTransform transform = CGAffineTransformMakeRotation(3.14159/2);
view.transform = transform;
CGRect contentRect = CGRectMake(-80, 80, 480, 320);
view.bounds = contentRect;

However, this doesn't work for UIView (in my testing). Is there something I have to do my AppDelegate in order for this/other code to function, or is there a better way of doing the same thing?

Thanks for any help!

like image 486
PF1 Avatar asked Aug 29 '09 02:08

PF1


2 Answers

this works for me

 CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI_2);
 self.view.transform = transform;

 // Repositions and resizes the view.
 CGRect contentRect = CGRectMake(0,0, 480, 320);
 self.view.bounds = contentRect;
like image 116
ashish Avatar answered Nov 10 '22 02:11

ashish


I had success with that:

CATransform3D rotationTransform = CATransform3DIdentity;
[view.layer removeAllAnimations];
rotationTransform = CATransform3DRotate(rotationTransform, angle, 0.0, 0.0, 1);
view.layer.transform = rotationTransform;
like image 30
Marco Avatar answered Nov 10 '22 00:11

Marco