0

I have a homeViewController (should always be in portrait mode) , which has four buttons to be redirected to a tar bar controller, which has four different viewController (first, second, third, fourth).

We want to have firstViewController and fourthViewController in portrait mode always. And secondViewController and thirdViewController in landscape mode always, also when we will go back to homeViewController form any of these viewControllers the homeViewController should always be in portrait mode.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
Kuldeep Bhimte
  • 961
  • 1
  • 10
  • 25

1 Answers1

1

You can use the -shouldAutrotate - Method of the ViewControllers to make sure they dont rotate when the device does. Just return NO, and the VC will always be displayed like your xib-file or storyboard specifies. Heres the docs: https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW124

and heres an example:

-(BOOL)shouldAutorotate{
    return NO;
}

EDIT: In Response to your coment:

UITabBarControllers wont forward the shouldAutorotate - Value to the ChildViewControllers. (As a sidenote, neither will a NavigationController). Your best bet is to subclass The TabBarController. Heres a link to a Stackoverflow-Post describing this. Have fun. IO6 doesn't call -(BOOL)shouldAutorotate

Community
  • 1
  • 1
katzenhut
  • 1,742
  • 18
  • 26
  • When I use shouldAutorotate with presentViewController it works. But when I use UITabBarController in which I have all my four view, it does not. Thanks in advance – Kuldeep Bhimte Nov 08 '13 at 15:23
  • @KuldeepBhimte - i need clarification: you mean when you transition manually (in code) it works, but when you transition with a segue from the TabBarController it doesn't? is that correct? – katzenhut Nov 08 '13 at 15:32
  • Yes, I have used shouldAutorotate method with both (while allocating view controllers with presentViewController and UITabBarController) Nut with presentViewController it orientation works properly and with tab bar it doesnot.. – Kuldeep Bhimte Nov 11 '13 at 06:04