How to restrict my app to landscape mode?

前端 未结 4 1393
不思量自难忘°
不思量自难忘° 2020-12-13 07:52

I have my iPad application created using the SplitView template. I wonder what is the best way to restrict my application to landscape mode?

I have tried overriding

相关标签:
4条回答
  • 2020-12-13 08:03

    I asked a question with a bounty of 500 that seems to be the same thing you're facing.

    From my limited experience it is much easier to make a landscape-only iPhone app than a landscape-only iPad app. I'm not sure why there is any difference, but the steps Apple says to take to make it landscape-only do not work on their own.

    0 讨论(0)
  • 2020-12-13 08:03

    Try this (it works):

    -(BOOL)shouldAutorotateToInterfaceOrientation(UIInterfaceOrientation)toInterfaceOrientation {
        if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
            return YES;
        }
        else 
        {
            return NO;
        }
    }
    
    0 讨论(0)
  • 2020-12-13 08:18

    Check out this iPhone app in landscape mode, if you haven't already. I was going to suggest simply adding UISupportedInterfaceOrientations to your Info.plist and specifying the two landscape orientations. But, apparently, this is not sufficient, according to answers to cited question.

    0 讨论(0)
  • 2020-12-13 08:18

    I believe this is a BUG, I faced this problem also. It is something to do with

    UIInterfaceOrientationLandscapeLeft
    

    To replicate this situation:

    1) Create a new iPad project using UISplitViewController template

    2) Edit info.plist

    Supported interface orientations
    -Landscape (left home button)
    -Landscape (right home button)
    

    3) DetailViewController.m

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    //    return YES;
     NSLog(@"RotateToInterface:[%d] vs LandscapeLeft[%d]", interfaceOrientation, UIInterfaceOrientationLandscapeLeft);
     return interfaceOrientation == UIInterfaceOrientationLandscapeLeft;
    }
    

    4) Run it....You will see a blank black view. and no matter how you turn. "UIInterfaceOrientationLandscapeLeft" never detected.

    By the way, nacho4d's adding BOOL check work-around is working. Thumbs UP :)

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