rockyliao
rockyliao

Reputation: 33

IOS6.0, SupportedInterfaceOrientations in Navigation base application

I have a navigation base application which was moved from Xcode 3.2 to 4.6 recently.

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 and I used that to force a particular views to UIDeviceOrientationLandscapeLeft only, and the others to UIDeviceOrientationPortrait only, so I add the fellowing code to corresponding ViewController:

-(BOOL)shouldAutorotate{
    NSLog(@"shouldAutorotate");
        return YES;
}
-(NSInteger)supportedInterfaceOrientations{
    NSLog(@"UIInterfaceOrientationMaskPortrait");
        return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate{
    NSLog(@"shouldAutorotate");
        return YES;
}
-(NSInteger)supportedInterfaceOrientations{
    NSLog(@"UIInterfaceOrientationMaskLandscapeLeft");
        return UIInterfaceOrientationMaskLandscapeLeft;
}

Then the ViewController pushed into the navigation only log "UIInterfaceOrientationMaskPortrait", and the view rotate when the device rotate. (this is not what I want) the ViewController show up by [self presentModalViewController:] can log both "shouldAutorotate" and "UIInterfaceOrientationMaskLandscapeLeft", and doesn't rotate when the device rotate.(this is what I want)

How can I make the view pushed into the navigation working correctly?

Upvotes: 1

Views: 242

Answers (2)

nsgulliver
nsgulliver

Reputation: 12671

if you are using UINavigationcontroller in your application and you need to have different interface orientations then it could mess up the interface orientation in the application, solution is to implement a custom UINavigationController and implement the interface orientation methods within that custom UINavigationController class, this will make your viewControllers rotate according to the orientation you set because your controllers are pushed from the UINavigationController.

for pushing the viewController on UINavigationController you should do like this

[self.navigationController pushViewController:yourViewController animated:YES];

I had the similar problem when using navigationController, my views were not rotating properly so i implemented the custom navigationController like this

CustomNavigationController.h

@interface CustomNavigationController : UINavigationController
@end

CustomNavigationController.m

@implementation CustomNavigationController

//overriding shouldRotate method for working in navController
-(BOOL)shouldAutorotate
{  
  return   [self.visibleViewController shouldAutorotate];   
}

-(NSUInteger)supportedInterfaceOrientations
{
   return [self.topViewController supportedInterfaceOrientations];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
   return [self.topViewController preferredInterfaceOrientationForPresentation];
}

Upvotes: 1

Yashesh
Yashesh

Reputation: 1752

Put the below code in your appDelegate Method:

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

}

Hope this will help you.

All the best !!!

Upvotes: 0

Related Questions