0

I think I have gone over almost every single post on this topic. So don't kill the question yet till you read. This question is for XCode 5 on iOS 7

I have an app that supports both landscape and portrait modes. In my projects Deployment info all orientations are checked.

When app launches I show

  • v1ViewController (which always should open in landscape mode)

When a user hits a button it takes them to

  • v3ViewController (which always should open in portrait mode)

The problem I have is that when app launches and I am holding the iphone in portrait mode it show this.

enter image description here

If I swtich the iphone in landscape mode it shows this.

enter image description here

How can I force my v1ViewController to always show landscape mode?

This is the code I have right now.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        return YES;
    }
    else 
    {
        return NO;
    }

}

But if I add this then the view always opens like the first picture I show and rotation has no effect.

- (BOOL)shouldAutorotate
{

    UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

    NSLog(@"interfaceOrientation: %d ...", interfaceOrientation);



    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        return YES;
    }
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        return YES;
    }
    else
    {
        return NO;
    }

}

 - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
 {
    return UIInterfaceOrientationLandscapeLeft;
 }

 -(NSUInteger)supportedInterfaceOrientations
 {
     return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
 }
4

1 回答 1

4

对于任何对我如何使其工作感兴趣的人,这就是我所做的。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

-(NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeLeft;
}
于 2013-09-24T18:41:07.300 回答