Question

How can I manually rotate a view using the autoresizingMasks, as if the user had rotated the phone and it had auto-rotated. Also I want it to be instant, no animation. I you want to know why I need this, look at my other question at iPhone Dev - keeping interface rotation.

Thanks!!

Was it helpful?

Solution

What you want to do here is use Affine transforms to rotate your View, I have accomplished this though i dont have the code infront of me at the moment. If you do a simple rotation youll find that your view will be cut off and not in the center like youd want, what you need to do here is set the anchor of your layer (play around with the value till you get what you want) in order for the view to appear where you want it. The way to approach this is just do the 90 degree affine transform rotation and see the effects it has on the view. This way you should be able to figure out where you layers anchor needs to be. Ill post some sample code here later when I am infront of my mac. Hope it helps

OTHER TIPS

I din't quite understand what you mean by

"... using the autoresizingMasks ..."

I did the same with UIIView animation. There are plenty of other techniques also out there. here is my code:

-(void)rotateToLandscape
{
UIWindow *win = [[UIApplication sharedApplication]keyWindow];
if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation)){
    [[[UIApplication sharedApplication] keyWindow] setBackgroundColor:[UIColor blackColor]];
    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    win.transform = CGAffineTransformIdentity;
    win.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    win.bounds = CGRectMake(0.0f, 0.0f, 480, 320);
    win.center = CGPointMake(160.0f, 240.0f);
    [UIView commitAnimations];
}   

}

// I hope the code doesn't need explanation.
//You can remove the animation statements to get the effect you want (un-animated).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top