Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 7 - Restrict landscape orientation only in one view controller

Tags:

ios

I need to open the first view controller only in portrait mode. As the rest view controllers will use both orientation. So i have added both orientation in plist file.

-(BOOL) shouldAutorotate {
    //Never called
}

- (NSUInteger) supportedInterfaceOrientations {
    //Never called
}

can any one tell me how to restrict

like image 305
Nabeel Thobani Avatar asked Nov 04 '13 13:11

Nabeel Thobani


People also ask

How do I lock landscape mode in iOS?

Swipe down from the top-right corner of your screen to open Control Center. Tap the Portrait Orientation Lock button to make sure that it's off.

How do I force landscape mode?

When on the main screen, under the orientation section, you will see a number of options like 'Auto-rotate OFF', 'Auto-rotate ON', 'Forced Portrait' and 'Forced Landscape'. As the names suggest, you can use these buttons as one-tap shortcuts to toggle the orientation of your device.

How do I lock device orientation 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.

How do I change a game from portrait to landscape?

The display orientation of the application may be locked. In the game, tap the “Settings” button in the toolbar. In the “Settings” display, scroll down to the “Lock Orientation” option. Review the current setting to ensure it is either set to “auto” or your preferred fixed orientation.


2 Answers

Fixed it simply by creating UINavigationController class and overriding

-(NSUInteger)supportedInterfaceOrientations
{
    AppDelegate *appDelegate = (AppDelegate *) [UIApplication sharedApplication].delegate;
    if(appDelegate.isOrientationOn) {
        return UIInterfaceOrientationMaskAll;
    }
    return UIInterfaceOrientationMaskPortrait;
}

Use this custom navigation controller class in root window and that's all.

like image 51
Nabeel Thobani Avatar answered Oct 29 '22 14:10

Nabeel Thobani


This will lock your View Controller's Orientation in Portrait Mode:

- (BOOL)shouldAutorotate
{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
like image 36
jbrodriguez Avatar answered Oct 29 '22 14:10

jbrodriguez