我有 2 个视图控制器、根和详细信息。根视图控制器支持横向和纵向,所以它有如下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait
|| interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight
|| interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
上面的代码非常适合根视图控制器。
如果根视图控制器正在显示,并且用户将设备旋转到横向模式,则视图会相应调整。从这一点开始,如果将我的详细视图控制器推入堆栈,它将以横向模式加载。但是,它不应该,因为我将它配置为仅支持纵向模式。我在详细视图控制器中使用以下代码:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}