I'm presenting a modal view with the code:
[self presentViewController:movieViewController animated:YES completion:^{
// completed
}];
Inside movieViewController, the controller is dismissed with:
[self dismissViewControllerAnimated:YES completion:^{
// back to previous view controller
}];
At the moment, all my view controllers can be viewed in portrait and the two landscape orientations.
How would I restrict all view controllers to portrait EXCEPT the modal view controller? So the modal view controller can be seen in the three orientations, and everything else in one.
Set the supportedInterfaceOrientations property of specific UIViewControllers like this: class MyViewController: UIViewController { var orientations = UIInterfaceOrientationMask. portrait //or what orientation you want override var supportedInterfaceOrientations : UIInterfaceOrientationMask { get { return self.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
You can configure which device orientation does your iOS app support in the Xcode target —> General —> Deployment Info section also. Just check the checkbox in the Deployment Info —> Device Orientation section.
Go it the main and select TARGETS then select Info tab (the plist) and open Supported inferface orientations (iPhone) the click on the ones that you do not need. Just leave Portrait(bottom home button) . That should make the UI stay one way.
In appDelegate:
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
special UINavigationController subclass (if you using navigation controller) with methods:
- (NSUInteger)supportedInterfaceOrientations {
if (self.topViewController.presentedViewController) {
return self.topViewController.presentedViewController.supportedInterfaceOrientations;
}
return self.topViewController.supportedInterfaceOrientations;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return self.topViewController.preferredInterfaceOrientationForPresentation;
}
each view controller should return it's own supported orientations and preferred presentation orientation:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
my app works in portrait, but video player opens as modal vc with:
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeLeft;
}
It works perfect for me, hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With