这将使您启动并运行。最终你真的应该继承这些 UIKit 类而不是使用类别,但不幸的是,这不适用于尚未为 iOS 6 修复的第三方库。这些类别应该适用于所有事情,而不需要你在其他人的代码中捣乱。
对于不涉及子类化(或编写类别)的问题,UITabBarController
我还没有看到任何解决方案。UINavigationController
不过,我希望存在一个。
确保在 Prefix.pch 文件的顶部导入三个 .h 文件(如果您选择将它们全部添加到单个文件中,则导入一个)。您必须确保尽快加载此代码!
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