- Home /
Unity in iOS Tab Bar Controller Orientation Issue
I'm modifying my iOS app to show Unity in one of my tabs. Things seem to be working properly except for a screen orientation issue where the orientation of iOS elements (tabs, status bar, etc) will be in portrait but the Unity view will be in landscape, and vice versa.
Here's what I've done:
I created a new `NewAppController.mm` that is a subclass of `AppController.mm` generated by Unity, and updated the `UIApplicationMain` method in `main.mm` to use `NewAppController.mm`
`application:didFinishLaunchingWithOptions` in `NewAppController.mm` does this:
[super application:application didFinishLaunchingWithOptions:launchOptions];
self.unityViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
UITabBarController *tabVC = [[UITabBarController alloc] init];
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:tabVC];
[[UIApplication sharedApplication] keyWindow].rootViewController = navVC;
[tabVC addChildViewController:self.unityViewController];
I'm not sure why the unity view isn't detecting the correct orientation and any ideas will help a lot.
Thanks!
Edit (11/19): I tested this on both iOS 5.1 and iOS 6 and they exhibit similar behaviors.
On iOS 5.1, the incorrect orientation occurs only when the iPad is in the upright position (instead of staying flat on the desk). The fix that worked for me was to comment out the line `[[NSNotificationCenter defaultCenter] postNotificationName: UIDeviceOrientationDidChangeNotification object: [UIDevice currentDevice]];` under `OpenEAGL_UnityCallback` in `AppController.mm`
However, iOS 6 works differently and the incorrect orientation occurs for both upright and flat position. I have not found a solution for it.