我的应用程序中有一个视图控制器。让它的第一个视图控制器,我的第一个视图控制器在手机中以纵向模式显示,当用户在横向模式下旋转手机时,第一个视图控制器也在横向模式下旋转。
它工作正常,现在我在第一个视图控制器上有一个按钮,当我触摸按钮时,第二个视图控制器就会出现。我只想做的是,即使第一个视图控制器处于横向模式,第二个视图控制器也应该始终显示为纵向模式。有没有什么方法我必须重写才能获得这个功能?
发布于 2013-01-07 18:29:07
在导航控制器中,控制器的方向取决于导航控制器的根控制器的方向。
您有两种可能性:
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];
}发布于 2013-01-07 19:24:06
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}在第二个视图中,控制器保留这个。
https://stackoverflow.com/questions/14193916
复制相似问题