【发布时间】:2013-02-14 04:16:37
【问题描述】:
我有一个UINavigationController,其中堆栈中的所有UIViewController 都是纵向的,除了最后一个是横向的。我当前的实现在推送时显示了纵向的最后一个视图控制器,但我可以旋转到横向,并且不能旋转回纵向。 如何在视图被推送时强制旋转为横向?
我的UINavigationController 子类:
@interface RotationViewController : UINavigationController
@end
@implementation RotationViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
if (self.topViewController.class == [LoadingViewController class])
{
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
if (self.topViewController.class == [LoadingViewController class])
{
return UIInterfaceOrientationLandscapeLeft;
}
return UIInterfaceOrientationPortrait;
}
@end
我只想要横向的视图控制器:
@implementation LoadingViewController
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
@end
其他视图控制器不实现这些方法中的任何一个。
【问题讨论】:
标签: ios cocoa-touch ios6