我想要执行以下操作:
ViewControllerA 不应进入水平方向 ViewControllerA 推送 ViewControllerB ViewControllerB 应该进入水平方向。
不确定要设置什么才能实现这一点。
最佳答案
在每个 UIViewController
中,您需要重写 shouldAutorotateToInterfaceOrientation
方法,并为您支持的每个界面方向返回一个 bool 值:
// ViewControllerA
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
// ViewControllerB
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait ||
interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
有关更多信息,请查看 UIViewController
class reference .
关于iphone - 如何强制水平方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3538796/