How do we dictate app orientation in iOS 8?

前端 未结 2 1580
囚心锁ツ
囚心锁ツ 2020-12-03 01:52

In iOS 7 we said:

// ViewController1:

-(NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorota         


        
相关标签:
2条回答
  • 2020-12-03 02:08

    The answer to part one (launching into landscape) is unchanged from iOS 7: everything depends on the order of possible orientations in the Info.plist file. So, let's say that View Controller 1 says this:

    -(NSUInteger)supportedInterfaceOrientations {
        return UIInterfaceOrientationMaskLandscape;
    }
    

    Then we will coherently launch into landscape if a landscape orientation comes first in the Info.plist's supported interface orientations:

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    

    One noteworthy change in iOS 8 is that by default the status bar is hidden when we're in landscape. But you can prevent this, if desired, with the appropriate override:

    -(BOOL)prefersStatusBarHidden {
        return NO;
    }
    

    That doesn't answer the second part of my question, which is how to force rotation when a view controller is presented. As I have explained in this answer, my sense is that this will become impossible in iOS 8. Your view controller and your views are expected to "adapt" — and so are you.

    EDIT: It looks like in seed 4 the ability to force app rotation on view controller presentation/dismissal is returning!

    0 讨论(0)
  • 2020-12-03 02:14

    Issue is likely in your *.plist file

    Check and what you want is to list the default/first launch orientation for a screen as

    Supported Interface Orientations:

    item 0 Landscape (right home button)

    item 1 Portrait (bottom home button)

    This "bug" I chased for days before I finally checked for the work UIInterface in global search in Xcode and notice I was listing orientations which my game doesn't support (Entire game is 100% Landscape Right)

    I got rid of Landscape Left which was the cause of GameCenter launch rotating to Landscape Left if I held the device in Landscape Left orientation physically.

    Problem solved.

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