如果您希望我们所有的导航控制器尊重顶视图控制器,则可以使用类别,因此您不必经过并更改一堆类名称。
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
正如一些评论所指出的那样,这是解决问题的快速解决方法。一个更好的解决方案是子类UinavigationController,并将这些方法放在其中。子类还有助于支持6和7。