1

i have a tabbar ios app. i want to make one of the tabs portrait only. how do i do that? i already tried the solution in How to force view controller orientation in iOS 8? and didn't help. I put that in view controller's .m code. This view controller has both a UIView and UITableView in it. pl see image below;enter image description here

thank you.

Community
  • 1
  • 1
user3282227
  • 131
  • 2
  • 10

2 Answers2

1

in your all viewcontroler write this code:

- (NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskAll; //allow rotate landscape, portrait
}

and write this code in in which viewconroller you want only portrait.

- (NSUInteger)supportedInterfaceOrientations
{ 
  return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown; // portrait only 
}

OR you can use this one:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ([self.window.rootViewController.presentedViewController isKindOfClass: [CompareViewController class]])
    {
        CompareViewController *compareController = (CompareViewController *) self.window.rootViewController.presentedViewController;

        if (compareController.isPresented)
            return UIInterfaceOrientationMaskLandscape;
        else return UIInterfaceOrientationMaskPortrait;
    }
    else return UIInterfaceOrientationMaskPortrait;
}
princ___y
  • 1,089
  • 1
  • 9
  • 27
  • Thanks for quick response. I'm trying out supportedInterfaceOrientationsForWindow() method. Will accept your answer if it works out. – user3282227 Oct 30 '15 at 06:01
  • Hi..i put the supportedInterfaceOrientationsForWindow() in my app's AppDelegate.m. I see that this method is getting called but the if() check isn't working in my case. Yes, I replaced the CompareViewController with mine. - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { NSLog() <== this comes if ([self.window.rootViewController.presentedViewController isKindOfClass: [CInfoViewController class]]) { NSLog(@"xx"); <=== never comes here return UIInterfaceOrientationMaskPortrait; } } – user3282227 Nov 01 '15 at 00:18
  • With ios 9 and xcode 7.1, I get this new warning if I compile with above method: warning: All interface orientations must be supported unless the app requires full screen. If i build by commenting out supportedInterfaceOrientationsForWindow(), that warning goes away. – user3282227 Nov 01 '15 at 02:16
0

Try to create extension of UITabbarController, and then override below 2 methods in extension:

supportedInterfaceOrientations
shouldAutorotate

And in both the methods: just validate, if self.selectedIndex = 'particular index' (the tab index, which you want portrait) and return accordingly.

Ankit Thakur
  • 4,739
  • 1
  • 19
  • 35