I did an App which is tab-based. Nothing needs to be on landscape mode but a couple of views. It worked OK on iOS5 and I was pretty happy with the result. However with iOS6 and without messing with anything, it now rotates all the views and the consequences are not nice.
Because its a tab-based app, the couple of view I need in landscape are modalViews. That way I didn't mess with the tabbar and I had only to chose portrait in the "Supported Orientations" setting on build options and set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
on the views I wanted landscape.
Now with iOS6 this views are also on portrait mode, no matter what and they do not show the landscape mode even if I rotate the device. Likewise, if I allow all the orientations on the "Supported orientations", they all rotate, no matter what I put on the method above.
On all the views I haven't check the box "Use Autolayout" on storyboards.
Any help here?
*EDIT** Now that I see it, the App I have on the device works fine. I've installed with a promo code, not from Xcode, only to see whether my customers are having problems or not. Fortunatelly they are not. The problem remains though.
The most important part of the documentation I found for this issue is:
When the user changes the device orientation, the system calls this method on the root view controller or the topmost presented view controller that fills the window
To make my app fully working for autorotation in iOS 6, I had to do the following:
1) I created a new subclass of UINavigationController, and added shouldAutorotate and supportedInterfaceOrientation methods:
// MyNavigationController.h:
#import <UIKit/UIKit.h>
@interface MyNavigationController : UINavigationController
@end
// MyNavigationController.m:
#import "MyNavigationController.h"
@implementation MyNavigationController
...
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}
...
@end
2) In the AppDelegate, I did use my new subclass to show my root ViewController (it is introScreenViewController, a UIViewController subclass) and did set the self.window.rootViewController, so it looks that:
nvc = [[MyNavigationController alloc] initWithRootViewController:introScreenViewController];
nvc.navigationBarHidden = YES;
self.window.rootViewController = nvc;
[window addSubview:nvc.view];
[window makeKeyAndVisible];
This is the alternative solution for iOS6 in case you are using the tab bar controller. It also shows that is NOT needed to override UINavigationController or even UITabBarController.
In your xyzAppDelegate.h add this interface:
@interface UITabBarController (MyApp)
@end
And in xyzAppDelegate.m add these methods:
@implementation UITabBarController (MyApp)
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
// your custom logic for rotation of selected tab
if (self.selectedIndex==...) {
return UIInterfaceOrientationMaskAll;
}
else {
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown;
}
}
@end
Also, set the root view controller for the app window:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[self.window setRootViewController:tabBarController];
Are you setting the rootViewController in the delegate? For example,
self.window.rootViewController = self.navigationController;
When I was doing some iOS6 testing it wouldn't work properly until I did that...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With