我的应用程序支持每4个方向,我有一个在LandscapeRight中的UIViewController.
我正在使用UINavigationController来推送UIViewController,我希望UIViewController仅在UIInterfaceOrientationLandscapeRight中,但是当我旋转手机时,它会切换回其他方向.
我正在使用UINavigationController来推送UIViewController,我希望UIViewController仅在UIInterfaceOrientationLandscapeRight中,但是当我旋转手机时,它会切换回其他方向.
- -(BOOL)shouldAutorotate{
- return NO;
- }
- -(NSUInteger)supportedInterfaceOrientations{
- return UIInterfaceOrientationLandscapeRight;
- }
- -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
- return UIInterfaceOrientationLandscapeRight;
- }
解决方法
只需删除那些shouldAutorotate,supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation.
并将此添加到您想要仅显示横向的viewcontroller.
- -(void)viewDidAppear:(BOOL)animated{
- [[UIDevice currentDevice] setValue:
- [NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
- forKey:@"orientation"];
- }
实际上,这是来自类似问题的解决方案.
How to force view controller orientation in iOS 8?