Locking Orientation Does Not Work on iPad iOS 8 Swift Xcode 6.2

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

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.

Lock orientation and disable rotation on iPad

The answer to my question was actually quite simple. You have to activate Requires full screen in Deployement Info of your project. After that the iPad behaves the same as the iPhone with this code.

iPad Multitasking support requires these orientations

iPad Multitasking support requires all the orientations but your app does not, so you need to opt out of it, just add the UIRequiresFullScreen key to your Xcode project’s Info.plist file and apply the Boolean value YES.

How to disable auto-rotation for specific View Controllers inside a Navigation Controller (Swift)?

I made an example project on how to do this: GitHub repo.

While @Sidetalker's answer is correct I think it lacks a bit of explanation.

Basically you create a Custom Class for your UINavigationController and assign it to UINavigationController in Storyboard. In the custom UINavigationController class you override the shouldAutorotate function and check if the topViewController is ViewController(the class of your UIViewController in Storyboard) of the class on which you want to disable autorotate.

In custom UINavigationController:

override func shouldAutorotate() -> Bool {
if !viewControllers.isEmpty {

// Check if this ViewController is the one you want to disable roration on
if topViewController!.isKindOfClass(ViewController) {

// If true return false to disable it
return false
}
}

// Else normal rotation enabled
return true
}

Why does my app rotate without animation?

According to UIWindow documentation;

If the window has an existing view hierarchy, the old views are
removed before the new ones are installed.

Source Link -> here

So, system automatically destroy while decide to no longer need your first RootViewController. You can handle transition like this;

if var topRootController = UIApplication.sharedApplication().keyWindow?.rootViewController {
while (topRootController.presentedViewController != nil) {
topRootController = topRootController.presentedViewController!
}
topRootController.presentViewController(homeController, animated: true, completion: nil)
}


Related Topics



Leave a reply



Submit