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 got same bug on my app, I figured it out with this solution
Firstly it didn't work but after some dig I have to do it on initial controller after splash screen.
Answer is OjbC language let me update it to Swift
override var shouldAutorotate: Bool {
return true
}
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
Don't forget that should on the initial view controller.
Setting the statusBarOrientation
of the UIApplication
seems to work for me. I placed it in the application:didFinishLaunchingWithOptions:
method in the app delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
application.statusBarOrientation = UIInterfaceOrientationPortrait;
// the rest of the method
}
I had a similar issue is with my app runs both in landscape and portrait with a UITabBarController as root view controller.
Whenever the app was launched when in Landscape mode, the view was incorrect.
All I had to do: - remove rootview controller assignment in the XIB. - Manually add it in once the app is launched:
(void)applicationDidFinishLaunching:(UIApplication *)application { application.statusBarHidden = YES;
[self.window setRootViewController:self.tabBarController];
That fixed the problem.
I only want my app to open in landscape mode (and not exhibit the problem you describe above on the iPhone 6 Plus), so I set Landscape (left home button)
and Landscape (right home button)
as the only orientations allowed in my app's PLIST file. This fixes the orientation problem when my app opens. However, I need my app to support portrait mode for one view only since I display a UIImagePickerController
in my app, which Apple requires to be shown in portrait mode on iPhone.
I was able to support portrait for that one view only, while keeping my app opening in landscape mode, by including the following code in AppDelegate
:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
return UIInterfaceOrientationMaskAllButUpsideDown;
} else {
return UIInterfaceOrientationMaskAll;
}
}
Please try the following code. Probably this problem caused by size of keywindow on landscape launch.
// in application:didFinishLaunchingWithOptions: ...
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]]; //<- ADD!!
I had the same issue when launching our app in landscape on an iPhone 6 Plus.
Our fix was to remove landscape supported interface orientations from the plist via project settings:
and implement application:supportedInterfaceOrientationsForWindow: in the app delegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Apparently the information in your plist is to specify what orientations your app is allowed to launch to.