Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Portrait orientation in all view controllers except in modal view controller

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.

like image 940
cannyboy Avatar asked Feb 26 '13 20:02

cannyboy


People also ask

How do you change to portrait mode in Swift?

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.

What is a UIViewController?

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.

How do I change the orientation of Xcode?

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.

How do you lock rotation on iPhone Swift?

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.


1 Answers

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!

like image 74
iiFreeman Avatar answered Oct 05 '22 22:10

iiFreeman