How can I display one UIView in landscape?

后端 未结 4 669
眼角桃花
眼角桃花 2020-12-13 11:08

I\'ve looked at every question so far and none seem to actually answer this question.

I created a UITabBarController and added several view controllers to it. Most

4条回答
  •  既然无缘
    2020-12-13 11:51

    Here's what I'm doing to do this:

    first, put this define at the top of your file, right under your #imports:

    #define degreesToRadian(x) (M_PI * (x) / 180.0)
    

    then, in the viewWillAppear: method

    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];     
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {  
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
        self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    }
    

    if you want that to be animated, then you can wrap the whole thing in an animation block, like so:

    [UIView beginAnimations:@"View Flip" context:nil];
    [UIView setAnimationDuration:1.25];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];     
    if (self.interfaceOrientation == UIInterfaceOrientationPortrait) {  
        self.view.transform = CGAffineTransformIdentity;
        self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
        self.view.bounds = CGRectMake(0.0, 0.0, 480, 320);
    }
    [UIView commitAnimations];
    

提交回复
热议问题