[英]How to disable portrait orientation on UINavigationController rootViewController
I have a class, HomeView, as the rootViewController of a UINavigationController on my iPad application. 我有一个类HomeView,作为iPad应用程序上UINavigationController的rootViewController。 Only landscape orientation is set in the info.plist file and HomeView does not implement
shouldRotateToInterfaceOrientation:
, however the view is rotating for both orientations while the simulator is rotating. 在info.plist文件中仅设置了横向方向,并且HomeView没有实现
shouldRotateToInterfaceOrientation:
但是在模拟器旋转时,视图在两种方向上都在旋转。
How do I only use the landscape orientations in my UIViewController? 如何只在UIViewController中使用横向方向?
If you do not implement shouldAutorotateToInterfaceOrientation: the runtime will call the method on the Super class, UIViewController . 如果未实现shouldAutorotateToInterfaceOrientation:运行时将在Super类UIViewController上调用该方法。
Instead you should respond appropriately to the method with the orientations you want to rotate to: 相反,您应该使用要旋转的方向对方法进行适当响应:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
BOOL shouldAutorotate = NO;
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft
|| interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
shouldAutorotate = YES;
}
return shouldAutorotate;
}
Take a look at the UIInterfaceOrientation reference page and the UIViewController's shouldAutorotateToInterfaceOrientation: reference page for more information. 请参阅UIInterfaceOrientation参考页和UIViewController的shouldAutorotateToInterfaceOrientation:参考页,以获取更多信息。
You shouldn't remove the shouldAutorotateToInterfaceOrientation method; 您不应该删除shouldAutorotateToInterfaceOrientation方法。 that will not stop the interface from rotating, it will only not execute any code that you could have in that method.
这不会阻止界面旋转,只会执行该方法中可能没有的任何代码。 You should instead try something like this (assuming that you don't ever want the interface to rotate):
相反,您应该尝试这样的操作(假设您永远不希望界面旋转):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return NO;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.