iPhone dev - Manually rotate view

后端 未结 2 598
遥遥无期
遥遥无期 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).

提交回复
热议问题