I find many question to force UIViewController to landscape as default: How to force a UIViewController to Portrait orientation in iOS 6 And try this:
- (BOOL)shouldAutorotate
{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
But when I use UIViewController inside UINavigationController, I can't force to landscape.Please help!
*Work NOT ok
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[navControl setNavigationBarHidden:YES];
self.window.rootViewController = navControl;
[self.window makeKeyAndVisible];
return YES;
}
*Work OK:
self.window.rootViewController = self.viewController;
You need to go to your plist file and set the orientations. You can also do this on your project file. The plist orientations settings will override all though.
In your plist you can set both orientation options to landscape button left and landscape button right.
Best way to do this is the create extend UINavigationController and write your orientation function inside the extended class.
Class Declaration:
Implementation of MyNavigationController
and use your extended like MyNavigationController as navigation controller to your rootviewcontroller.
So your application delegate didfinishlounchingwithoptions code will be as follow.
Only way you can provide different orientation for two different view with same navigation controller isto reload the navigation controller itself. So if you add two methods
and call these function after pushing and pop views.
Note:- I don't know whether it is a good way or bad way.