我启动了一个示例项目并将以下代码添加到我的 View Controller 中。启动后屏幕将为横向。 然后我转到 Storyboard,单击我唯一的 View -> 编辑器 -> 嵌入 -> 导航 Controller 。再次启动该程序:屏幕将处于纵向状态,并且无论我如何尝试都不会更改为横向。这是为什么? (所有方向都在我的 plist 中启用。)
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
@end
最佳答案
在 iOS 6 中,规则是一旦您进入 UINavigationController,此 View Controller (ViewController) 的 supportedInterfaceOrientations
就不再相关。唯一咨询的是:
应用程序 (Info.plist)。
应用委托(delegate) (
application:supportedInterfaceOrientationsForWindow:
)Root View Controller ,在您的例子中现在是 UINavigationController
现在,我不完全理解为什么你的 UINavigationController 给你一个仅纵向的结果。但我确实知道,如果您想控制 UINavigationController 对旋转的操作,则必须子类化 UINavigationController,使此导航 Controller 成为子类的实例,并放置 supportedInterfaceOrientations
代码到你的子类中。
注意我尝试按照您所说的操作,在我的机器上,导航 Controller 确实对所有三个标准方向执行补偿旋转。所以我不明白为什么你说这只是肖像。然而,答案仍然是一样的。
关于ios - 嵌入导航 Controller 后 View 不会旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16306528/