No Name
No Name

Reputation: 1543

Force portrait in one view controller makes other to be in portrait initially

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

Upvotes: 2

Views: 738

Answers (3)

Kalpesh
Kalpesh

Reputation: 5334

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;
 }

Upvotes: 0

Anil Varghese
Anil Varghese

Reputation: 42977

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

Check this

Upvotes: 0

Nitin Gohel
Nitin Gohel

Reputation: 49730

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

Upvotes: 1

Related Questions