在iOS 8之前,我们将以下代码与supportedInterfaceOrientations和shouldAutoRotate委托方法结合使用,以强制应用程序定向到任何特定的定向。我使用下面的代码片段以编程方式将应用程序旋转到所需的方向。首先,我正在更改状态栏的方向。然后,只需显示并立即关闭模式视图,就可以将视图旋转到所需的方向。
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
UIViewController *c = [[UIViewController alloc]init];
[self presentViewController:vc animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
但这在iOS 8中失败了。此外,我在堆栈溢出中看到了一些答案,人们建议我们从iOS 8开始应该始终避免这种方法。
更具体地说,我的应用程序是一个通用类型的应用程序。总共有三个控制器。
我们正在使用导航控制器进行页面导航。从第一个视图控制器,在一个按钮单击动作上,我们将第二个推入堆栈。因此,当第二个视图控制器到达时,无论设备方向如何,应用程序应该只锁定在横向方向。
下面是我在第二个和第三个视图控制器中的shouldAutorotate
和supportedInterfaceOrientations
方法。
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeRight;
}
-(BOOL)shouldAutorotate {
return NO;
}
在iOS 8的特定方向上,有没有更好的锁定视图控制器的方法。请帮助!!
https://stackoverflow.com/questions/26357162
复制相似问题