Reputation: 1
I have a presented a navigation controller, in which the root view controller i,e. VC1 is supported for both landscape & portrait orientations. When i push another view controller in landscape the i,e. VC2 which supports only portrait mode, come back to the VC1, the view will be turned to portrait. But i am still in the landscape mode. Please help me to solve this on iOS 6 issue.
Please check the below code.
MyViewController1 *theController =[[MyViewController1 alloc] init];
UINavigationController *navCntlr = [[UINavigationController alloc] initWithRootViewController:theController];
[self.navigationController presentViewController:navCntlr animated:YES completion:nil]; [theController release];
[navCntlr release];
in MyViewController1
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
in VC2/MyViewController2 i have added the below code.
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
i have subclassed the root navigation bar as well.
Upvotes: 0
Views: 720
Reputation: 1286
Actually this was identified as a bug in IOS6 happens with ImageViewController which only supports Portrait orientation ... so i spent lot of time and found a way around the same....
hope this helps so first things first...
add a property in your AppDelegate.h
@property BOOL model;
then in AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.model=NO;
return YES;
}
also add this method in AppDelegate.m
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(!self.model)
return UIInterfaceOrientationMaskLandscape; //or needed orientation
else
return UIInterfaceOrientationMaskAllButUpsideDown;
}
then in your view controller before presenting the VC2
implement this code...
AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
appdelegate.model=YES;
and then you just change the value in the viewWillDisappear of VC2
AppDelegate *appdelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
appdelegate.model=NO;
Upvotes: 2