1

I am using UINavigationController in my application and my first controller called A and it is strict to portrite only and there is a button in my A controller.Once I click on the button I am creating instance to the another view controller called B. After creating the instance for B I am presenting modally using below method

[self presentViewController:BInstance animated:YES completion:^{
            NSLog(@"completed");
        }];

My B controller can able will support all the orientations, this is expected, till the ios5.1 and earlier versions. Now I am trying to run my project on the ios6 using Xcode4.5 it is not getting rotated I am looking forward to solve the issue I found some of the blogs about shouldAutorotateToInterfaceOrientation: method got deprecated from the latest ios6. I used alternative also

-(BOOL)shouldAutorotate{
    return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}

But still there is not much expected results.

Question: What makes my B controller will work for all orientations even my Parent A works only for portrite.

Thanks In advance All your suggestions/advice useful on this.

ajay
  • 3,245
  • 4
  • 31
  • 59

1 Answers1

5

First of all, in AppDelegate, write this. THIS IS VERY IMP

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
     return (UIInterfaceOrientationMaskAll);
}

Then, For UIViewControllers, in which you need only PORTRAIT mode, write these functions

- (BOOL)shouldAutorotate
{
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskPortrait);
}

For UIViewControllers, which require LANDSCAPE too, change masking to All.

- (NSUInteger)supportedInterfaceOrientations
{
    return (UIInterfaceOrientationMaskAllButUpsideDown);
    //OR return (UIInterfaceOrientationMaskAll);
}

Now, if you want to do some changes when Orientation changes, then use this function.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{

}
mayuur
  • 4,736
  • 4
  • 30
  • 65
  • Thanks for this I am checking. – ajay Oct 03 '12 at 10:36
  • I have tried it and then written... So it should work. Did you return YES for shouldAutorotate method in the class where you want LANDSCAPE? Could you post your code? – mayuur Oct 03 '12 at 11:41
  • 1
    +1 now its working..along with all your steps need to include one more step window.rootviecontroller have to be set.Thanks for this. – ajay Oct 03 '12 at 12:00