This will get you up and running. Ultimately you really should subclass these UIKit classes instead of using categories, but unfortunately that will not work for third party libraries which are not yet fixed for iOS 6. These categories should work for everything without requiring you to muck about in other people's code.
I have yet to see any solution for the UITabBarController
or UINavigationController
issues that do not involve subclassing (or writing a category). I wish one existed, though.
Make sure you import the three .h files (or one if you choose to add them all to a single file) at the top of your Prefix.pch file. You must make sure this code is loaded ASAP!
UITabBarController+LegacyRotation.h
#import <UIKit/UIKit.h>
@interface UITabBarController (LegacyRotation)
@end
UITabBarController+LegacyRotation.m
#import "UITabBarController+LegacyRotation.h"
@implementation UITabBarController (LegacyRotation)
- (NSUInteger)supportedInterfaceOrientations
{
return [self.selectedViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate
{
return [self.selectedViewController shouldAutorotate];
}
@end
UINavigationController+LegacyRotation.h
#import <UIKit/UIKit.h>
@interface UINavigationController (LegacyRotation)
@end
UINavigationController+LegacyRotation.m
#import "UINavigationController+LegacyRotation.h"
@implementation UINavigationController (LegacyRotation)
- (NSUInteger)supportedInterfaceOrientations
{
return [self.topViewController supportedInterfaceOrientations];
}
- (BOOL)shouldAutorotate
{
return [self.topViewController shouldAutorotate];
}
@end
UIViewController+LegacyRotation.h
#import <UIKit/UIKit.h>
@interface UIViewController (LegacyRotation)
@end
UIViewController+LegacyRotation.m
#import "UIViewController+LegacyRotation.h"
@implementation UIViewController (LegacyRotation)
- (NSUInteger)supportedInterfaceOrientations
{
NSUInteger ret = 0;
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) {
ret |= UIInterfaceOrientationMaskPortrait;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) {
ret |= UIInterfaceOrientationMaskPortraitUpsideDown;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) {
ret |= UIInterfaceOrientationMaskLandscapeLeft;
}
if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) {
ret |= UIInterfaceOrientationMaskLandscapeRight;
}
return ret;
}
- (BOOL)shouldAutorotate
{
return YES;
}
@end