First, you need to create a category:
UINavigationController+Rotation_IOS6.h
#import <UIKit/UIKit.h>
@interface UINavigationController (Rotation_IOS6)
@end
UINavigationController+Rotation_IOS6.m:
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
@end
Then, you implement these methods in your class that you want to be only landscape:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
In case you're using a UITabBarController, just replace the UINavigationController for UITabBarController.
This solution worked nice for me after a long search! I was in the same situation as you are now!
EDIT
So, I saw your sample. You need to make some changes.
1 - Create a new class for the UINavigationController category. Name the class UINavigationController+Rotation_IOS6 (.h and .m)
2 - You don't need to implement the method preferredInterfaceOrientationForPresentation
. Your category should look like this:
#import "UINavigationController+Rotation_IOS6.h"
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
@end
3 - In the class you want to rotate only in landscape, include this in the implementation, exactly like this:
// Rotation methods for iOS 6
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
4 - I would advice to also include the method for autorotation for iOS 5 inside the class you want in landscape:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}