ios portrait and landscape mode
-
21-12-2019 - |
Question
I have the following scenario:
From appDelegate I do:
firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *firstNavController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
firstViewController - needs to be only in portrait mode
In order to accomplish this I did:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate
{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
From firstViewController
I am pushing another view controller which needs to have both portrait and landscape capabilities.
The secondViewController
acts as expected - in portait and landscape mode
I have issues with firstViewController which is displayed in landscape mode too, though I've restricted it to Portrait mode. What am I doing wrong?
Solution
Add the UINavigationController Category with following method in your project
#import "UINavigationController+MyNavigation.h"
@implementation UINavigationController (MyNavigation)
-(BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
This solved my problem.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow