locking orientation does not work on ipad ios 8 swift xcode 6.2

后端 未结 5 1540
广开言路
广开言路 2020-12-06 04:24

I locked the app orientation to portrait from the general app setting like this

\"portrait\"

but still

相关标签:
5条回答
  • 2020-12-06 04:36

    You don't need extra code, I'm working on Xcode 7.0.1, I noticed that when I lock screen orientation to only portrait, it locks only in iPhones, to lock it in iPads also, you need to select iPad from Devices (instead of Universal) and check portrait and uncheck the others and then return Devices to Universal again, as I found that Universal only reflect in iPhones, it maybe some kind of bug in Xcode.

    0 讨论(0)
  • 2020-12-06 04:53

    You can override your view controller property shouldAutorotate

    override var shouldAutorotate: Bool {
        return false 
    }
    

    If your view controller is embedded in a Navigation controller you can create a custom Navigation controller:

    class PortraitNavigationController: UINavigationController {
    
        override var shouldAutorotate: Bool {
            return false 
        }
        /*
        // MARK: - Navigation
    
        // In a storyboard-based application, you will often want to do a little preparation before navigation
        override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            // Get the new view controller using segue.destinationViewController.
            // Pass the selected object to the new view controller.
        }
        */
    }
    
    0 讨论(0)
  • 2020-12-06 04:57

    I also had same problem. What worked for me was -> Select iPad instead of Universal in Device Type -> Uncheck the other three options except Portrait -> Select Universal again. Done.

    0 讨论(0)
  • 2020-12-06 04:58

    This would be a comment added to Mohammed Elrashidy solution but I don't have the reputation to make comments. I am using XCode 9.1 and Swift 3.

    My app requires some graphing screens to autorotate but all the other screens to remain fixed. My issue was that the "iPad" device configuration in General > Deployment Info was configured inconsistently with the iPhone and Universal devices. I had "Portrait", "Landscape Left" and "Landscape Right" checked for iPhone and Universal but all of the orientations checked for iPad (including "Upside Down"). Simply unchecking "Upside Down" caused the iPad device to honor the shouldAutorotate and supportedInterfaceOrientations calls in my Swift logic.

    My Info.plist now looks like the following and I can programmatically turn autorotation on or off for the iPad.

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    
    0 讨论(0)
  • 2020-12-06 04:59

    I just wanted to add something else you need to do, after fixed the issue following the above solution:

    In XCode, make sure you also check the "Requires Full Screen" checkbox under General > Targets.

    Reference: iPad Multitasking support requires these orientations

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