How can I display one UIView in landscape?

后端 未结 4 661
眼角桃花
眼角桃花 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:45

    Override the Orientation method in your controller class and force it to Landscape like this :

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    {
        // Overriden to allow any orientation.
        return UIInterfaceOrientationIsLandscape(interfaceOrientation);
    }
    

    Simple and efficient !

    0 讨论(0)
  • 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];
    
    0 讨论(0)
  • 2020-12-13 11:56

    shouldAutorotateToInterfaceOrientation only work if all the view in the tabbarcontroller or all the view controllers in the navigationcontroller agree upon a rotation.

    0 讨论(0)
  • 2020-12-13 11:59

    An post on a forum that might help. Short answer is you have to manually rotate your view or controller once the view has been drawn, in the viewWillAppear: method

    CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(degreesToRadian(90));
    landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +80.0, +100.0);
    
    [[appDelegate navController].view setTransform:landscapeTransform];
    
    0 讨论(0)
提交回复
热议问题