2

The root view controller of navigation controller supports only portrait orientation and other controllers supports all orientation.Now if i am on the root view controller and the DEVICES is in landscape and if i push next view controller that opens in portrait that should open in landscape as it supports all orientation.

Please help me with this.

Using iPhone 4s iOS6.1.3

Nilesh
  • 1,493
  • 18
  • 29

3 Answers3

1

you can check Device orientation in your first screen after login viewcontroller using bellow code:-

-(void)viewWillAppear:(BOOL)animated
    {
        [self willRotateToOrientation:[[UIDevice currentDevice] orientation]];  
        [super viewWillAppear:YES];
    }


- (void)willRotateToOrientation:(UIInterfaceOrientation)newOrientation {
        if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
        {
            if (newOrientation == UIInterfaceOrientationLandscapeLeft || newOrientation == UIInterfaceOrientationLandscapeRight) {

              //set your landscap View Frame
                [self supportedInterfaceOrientations];

            }



        }
        else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation))
        {
            if(newOrientation == UIInterfaceOrientationPortrait || newOrientation == UIInterfaceOrientationPortraitUpsideDown){
      //set your Potrait View Frame
                [self supportedInterfaceOrientations];

            }
        }
        // Handle rotation
    }

sor when you load this viewcontroller it check first device oriantation and then load it's related frame

Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
  • Thanks for your answer man, i am doing the same thing but it doesn't help. :( anyways i am upvoting your answer as it might help to some one else. – Nilesh May 23 '13 at 10:12
0

I think this is the issue related to the orientation changes in iOS6. You need to subclass the UINavigationController

Check this

Community
  • 1
  • 1
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110
0

1 . You have to create sub class of UINavigationController. add Following method.. Take one boolean variable to check whether it support for all orientation or not and change its value.

 @implementation NavigationControllerViewController

- (BOOL)shouldAutorotate
{
return YES;
}      

- (NSUInteger)supportedInterfaceOrientations
{
AppDelegate *appdelgate=[[UIApplication sharedApplication]delegate];

if (appdelgate.issuppoertAll) {
    // for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
    return UIInterfaceOrientationMaskAll;

}
return UIInterfaceOrientationMaskPortrait;

  }
 @end

2 when you navigate form root view controller to other view controller

use this code , when you want to forcefully change its orientation.i.e lanscape to portrait

      obj_viewcontroller        = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self presentModalViewController:obj_viewcontroller animated:NO];
    [self dismissModalViewControllerAnimated:NO];

    [self.navigationController pushViewController:obj_viewcontroller animated:NO];

3 In second view controller you have to change boolean variable value

-(void)viewWillAppear:(BOOL)animated
{
appdelgate.issuppoertAll=YES;
  }

4 Add this method into all view controller and set orientation as per your need.

- (NSInteger)supportedInterfaceOrientations 
{
return UIInterfaceOrientationMaskPortrait;
 }
Kalpesh
  • 5,336
  • 26
  • 41