0

As title says, Is it possible to enable and disable the landscape mode on the same ViewController? I need it because I have a UIWebView that has the possibility to open the video player in fullscreen and the player should have the possibility to rotate (if switched to fullscreen), but since my ViewController has Landscape disabled it doesn't, I managed to have a callback when the user opens the video player on fullscreen but I didn't find anything about enabling/disabling Landscale after the viewDidLoad.

LS_
  • 6,763
  • 9
  • 52
  • 88
  • Check this answer http://stackoverflow.com/questions/17466048/how-to-allow-only-single-uiviewcontroller-to-rotate-in-both-landscape-and-portra – Ganesh Somani Jun 11 '15 at 10:01

1 Answers1

0

This is possible.

In your target settings / plist you have to enable all possible UIInterfaceOrientation's

enter image description here

In your UINavigationController subclass block all rotation to your needs:

#pragma mark - Rotation

-(BOOL)shouldAutorotate
{
    return NO;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

In any UIViewController you want to enable a UIInterfaceOrientation overwrite the methods:

#pragma mark - Rotation

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight);
}
Jasper
  • 7,031
  • 3
  • 35
  • 43
  • The problem is that the UIWebView is inside another viewController that I don't want to be able to rotate, I want to have a method that called enable/disable the rotation, Do you think that calling ShouldAutorotate with yes or no would work? – LS_ Jun 11 '15 at 10:31
  • You said you have a callback to know when fullscreen has been entered/left. You could use a BOOL to keep track and return the value you want in those methods – Jasper Jun 11 '15 at 10:36
  • You will need some tweaking of the above code, but that is the basic on how to have 1 UIViewController rotate – Jasper Jun 11 '15 at 10:39