Reputation: 412
I have a navigation controller with a rootviewcontroller with portrait orientation. Then i want to push a second viewcontroller to the stack with landscape orientation. Sadly i found no way to force the app to recheck supportedInterfaceOrientations
. So the landscape viewcontroller is shown in protrait until the user rotates his device into landscape.
I prepared a test project: https://github.com/buechner/InterfaceOrientationTest
Is it even possible to automatically change the orientation within a navigationcontroller stack?
Upvotes: 2
Views: 785
Reputation: 1504
You can present a ViewController
within LandscapeViewController
to forcefully make it landscape
Use following line of the code in your viewDidLoad
of LandscapeViewController
self.performSelector(#selector(LandscapeViewController.launchLandscapeScreen), withObject: nil, afterDelay:1)
add following method in your LandscapeViewController
func launchLandscapeScreen() -> Void{
let viewController = UIViewController()
self.presentViewController(viewController, animated: false, completion: nil)
self.dismissViewControllerAnimated(false, completion: nil)
}
Upvotes: 2
Reputation: 685
It could be done but you'll have to make UIStoryboardSegue subclass
Make a subclass of UIStoryBoradSegue
and override perform()
override func perform() {
let sourceVC = self.sourceViewController
let destonationVC = self.destinationViewController
sourceVC.navigationController!.presentViewController(destonationVC, animated: true, completion: nil)
}
In your NavigationControllerSubclass change shouldAutoRotate
and supportedInterfaceOrientations
public override func shouldAutorotate() -> Bool {
return (self.topViewController?.shouldAutorotate())!
}
public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return (self.topViewController?.supportedInterfaceOrientations())!
}
while connecting Segue from viewControllers select your segue subclass
4.add shouldAutorotate
and supportedInterfaceOrientations
methods in every class to
override func shouldAutorotate() -> Bool {
return true
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return .Portrait // or landscape in case you want orientation to be landscape
}
Upvotes: 0