为 UINavigationController 创建一个类别,其中包括以下方法:
(适用于 iOS 6 和 iOS 5)
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return [self.topViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
}
然后在你的控制器中实现这些方法
第一的:
- (BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
if (RUNNING_IPAD) {
return UIInterfaceOrientationMaskAll;
}
else {
return UIInterfaceOrientationMaskAllButUpsideDown;
};
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (RUNNING_IPAD) {
return YES;
}
else {
return toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown;
}
}
第二:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
return NO;
}
项目的旋转设置应如下所示: