我的应用中有一个视图控制器。让它的第一个视图控制器,我的第一个视图控制器在手机中以纵向模式出现,当用户在横向模式下旋转手机时,第一个视图控制器也以横向模式旋转。
它工作正常,现在我在第一个视图控制器上有一个按钮,当我触摸按钮时,第二个视图控制器出现。我只想做第二个视图控制器应始终以纵向模式出现,即使第一个视图控制器处于横向模式。 是否有任何方法我必须覆盖才能获得此功能?
答案 0 :(得分:1)
在导航控制器中,控制器的方向取决于导航控制器根控制器的方向。
您有两种可能性:
让根控制器的shouldAutorotateToInterfaceOrientation:
返回不同的值,具体取决于实际显示的控制器;
对视图控制器的视图使用转换,以便将其旋转。
我会尝试第一种方式,开始。请查看this post以了解如何操作(只需忽略UITabBarController
内容),或尝试此操作(只需将消息中继到导航层次结构中的顶级控制器):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return [self.navigationController.topController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}
为了在iOS6上获得相同的结果,请尝试定义以下方法:
-(NSUInteger)supportedInterfaceOrientations {
return [self.navigationController.topController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [self.navigationController.topController preferredInterfaceOrientationForPresentation];
}
答案 1 :(得分:1)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
在第二个视图控制器中保留此信息。