1

All my project allow to view app in landscape/portrait mode, but for one View Controller I want to disable this function and show it only in portrait orientation.

I have tried shouldAutorotate and supportedInterfaceOrientations, but it don't work.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
user2058653
  • 703
  • 2
  • 9
  • 23
  • have you check [this](http://stackoverflow.com/questions/21348964/ios-7-display-a-view-as-portrait-only-for-application-built-in-xamarin) – abmussani May 06 '14 at 09:59

3 Answers3

5

If you want different orientation for view controllers, In AppDelegate add this method -

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
    NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

    if(self.window.rootViewController){
        UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
        orientations = [presentedViewController supportedInterfaceOrientations];
    }

    return orientations;
}

and in your ViewController -

-(BOOL)shouldAutorotate{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
    return (UIInterfaceOrientationMaskAll);//Change this according to your need
}

Hope this will help.

Bharat
  • 2,987
  • 2
  • 32
  • 48
  • Old post, I know; however, I am recieving an error with the AppDelegate code: `Conflicting return type in implementation of 'application:supportedInterfaceOrientationsForWindow:': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned long')` – JDev Feb 02 '17 at 15:33
  • Managed to fix it by changing the declaration of your function from `NSUInteger` to `UIInterfaceOrientationMask`. Here's what I mean: `- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {` – JDev Feb 02 '17 at 16:31
0

enter image description here Go to your project -> General -> Device Orientation and just select only portrait in General settings.

Deep Gami
  • 508
  • 3
  • 13
  • 3
    He is asking only one VC to support only portrait and all other to support portrait/landscape . – Blios May 06 '14 at 10:11
0

You have

UINavigationController  -- UIViewController1
                        -- UIViewController2

You have to subclass UINavigationController and implement shouldAutorotate and supportedInterfaceOrientations. In UIViewController1,2 allow to rotate whatever orientations which you want.

nmh
  • 2,497
  • 1
  • 15
  • 27