iOS - 将特定的UIViewController锁定到特定方向 [英] iOS - Lock a specific UIViewController to a specific orientation

查看:247
本文介绍了iOS - 将特定的UIViewController锁定到特定方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序支持每4个方向,我有一个 UIViewController ,它位于 LandscapeRight 中。
我使用 UINavigationController 推送 UIViewController ,我想要 UIViewController 仅在 UIInterfaceOrientationLandscapeRight 中,但当我旋转手机时,它会切换回其他方向。

My application supports every 4 orientation, I have a UIViewController which is in LandscapeRight. I am using UINavigationController to push that UIViewController, i want that UIViewController to be only in UIInterfaceOrientationLandscapeRight but when I rotate the phone, it switches back to other Orientation.

-(BOOL)shouldAutorotate{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationLandscapeRight;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}


推荐答案

只需删除那些shouldAutorotate,supportedInterfaceOrientations和preferredInterfaceOrientationForPresentation。

just remove those shouldAutorotate, supportedInterfaceOrientations and preferredInterfaceOrientationForPresentation.

并将其添加到您想要仅显示横向的viewcontroller。

and add this to the viewcontroller you want to display landscape only.

-(void)viewDidAppear:(BOOL)animated{

    [[UIDevice currentDevice] setValue:
     [NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
                                forKey:@"orientation"];
} 

实际上,这是来自类似问题的解决方案。
如何在iOS 8中强制查看控制器方向?

actually, this is from a similar question with solution here. How to force view controller orientation in iOS 8?

这篇关于iOS - 将特定的UIViewController锁定到特定方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆