如何在UINavigationController rootViewController上禁用纵向方向 [英] How to disable portrait orientation on UINavigationController rootViewController

查看:104
本文介绍了如何在UINavigationController rootViewController上禁用纵向方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类HomeView,作为iPad应用程序上UINavigationController的rootViewController.在info.plist文件中仅设置了横向方向,而HomeView并未实现shouldRotateToInterfaceOrientation:,但是在模拟器旋转时,视图在两种方向上都在旋转.

I have a class, HomeView, as the rootViewController of a UINavigationController on my iPad application. 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.

如何仅在UIViewController中使用横向?

How do I only use the landscape orientations in my UIViewController?

推荐答案

如果您未实现 shouldAutorotateToInterfaceOrientation:,则运行时将在Super类( UIViewController )上调用该方法

If you do not implement shouldAutorotateToInterfaceOrientation: the runtime will call the method on the Super class, 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.

这篇关于如何在UINavigationController rootViewController上禁用纵向方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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