The actual title for this question is longer than I can possibly fit:
Launching an app whose root view controller only supports portrait-orientation but which otherw
I'm in the same situation, and doing [self.window setFrame:...] doesn't work for me.
Adding the following at the end of application:didFinishLaunchingWithOptions is the only thing I've found that works. It makes the screen blink and isn't exactly clean and efficient.
I added this at the end of application:didFinishLaunchingWithOptions:
UIViewController *portraitViewController = [[UIViewController alloc] init];
UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:portraitViewController];
[self.navController presentViewController:nc animated:NO completion:nil];
[self.navController dismissViewControllerAnimated:NO completion:nil];
[UIViewController attemptRotationToDeviceOrientation];
Just Remove All the items in Supported interface orientation except what you want (i need only Portrait) in info.plist , it will work for me
No luck for me the workaround by Jared using a generic container view controller. I've already subclassed tab bar controller with supportedInterfaceOrientations with no luck as well. Regardless of orientation of the 6+ after launch the tab bar's window is reporting frame = (0 0; 736 414)
So far the only workaround I've found is to force the window frame after makeKeyAndVisible
[self.window makeKeyAndVisible];
self.window.frame = CGRectMake(0, 0, MIN(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)), MAX(CGRectGetWidth(self.window.frame), CGRectGetHeight(self.window.frame)));
just call [application setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO]; in app delegate method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in fact the device now is UIInterfaceOrientationPortrait after Launching ,if you touch an inputField ,the keyboard is portrait layout
I had a very similar problem. I wanted to force portrait mode everywhere except for playing back videos.
What I did was:
1) to force the app orientation to be in portrait in the AppDelegate:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if ([window.rootViewController.presentedViewController isKindOfClass:[MPMoviePlayerViewController class]])
{
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
2) launching an empty modal view controller fixed the problem in my case. I launch it in the viewDidLoad of the first view controller that is on the root of my NavigationViewController (the first view controller visible after the application launches):
- (void)showAndHideNamelessViewControllerToFixOrientation {
UIViewController* viewController = [[UIViewController alloc] init];
[self presentViewController:viewController animated:NO completion:nil];
[viewController dismissViewControllerAnimated:NO completion:nil];
}
For myself, I was having the same issue as jaredsinclair, but subclassing a UIViewController
with the supportedInterfaceOrientations
method was not solving the issue. Instead I did exactly what he did in my appDidFinishLaunching
method of my AppDelegate
and added my UITabBarController
as a child to a normal UIViewController
rather than his subclass and it worked!