iPhone dev - Manually rotate view

后端 未结 2 577
遥遥无期
遥遥无期 2021-01-15 13:32

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

相关标签:
2条回答
  • 2021-01-15 13:41

    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).

    0 讨论(0)
  • 2021-01-15 13:44

    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

    0 讨论(0)
提交回复
热议问题