Scofield Tran
Scofield Tran

Reputation: 840

Force a UIViewController just landscape in iOS 9

I have an app supports both orientation portrait and landscape. But in a viewcontroller I JUST want it present in LANDSCAPE mode. I try overriding some methods for changing orientation such as

- (BOOL)shouldAutorotate {
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return (UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        return YES;
    }
    return NO;
}

But none of them are called in iOS 9. Therefore, this viewcontroller present both portrait and landscape. On contrary, it works perfectly in iOS 8.

So annoying, is there anyway to force just a viewcontroller presented in landscape mode in iOS 9

UPDATE: As Ronak Chaniyara's answer, I solved my problem, just one controller is in landscape mode. Now I face another problem. If I want to force one controller just in portrait mode, I implement these methods in the controller but it's still rotated if I rotate screen.

Is the solution still work with portrait mode, or I have to find another approach to force a controller just in portrait mode

Upvotes: 1

Views: 3332

Answers (3)

Shital Sharma
Shital Sharma

Reputation: 17

In this way, you can do:

  1. Go to target setting
  2. Go to development info
  3. Change device orientation to landscape and uncheck all other option.

Hope this help you

Upvotes: 1

Ronak Chaniyara
Ronak Chaniyara

Reputation: 5436

I think issue will be you have defined the allowed orientations in info.plist which apparently overrides anything you do anywhere else throughout the project.

To correct the issue I removed the entries from info.plist and defined them in the project settings. Now everything works as expected.

Hope this helps.

Upvotes: 4

Clément Cardonnel
Clément Cardonnel

Reputation: 5317

Look at your info.plist file. Here you have a key named "Supported Interface Orientation" with a group for the iPhone version and another for the iPad.

Here you can delete the value "Portrait (bottom home button)", and replace it by "Landscape (left home button)" or "Landscape (right home button)".

I hope it helped!

Upvotes: 1

Related Questions