如何在UINavigationControllers中锁定方向 [英] How to lock orientation in UINavigationControllers

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

问题描述

由于 iOS 6 中不推荐使用 ShouldAutorotateToInterfaceOrientation ,我无法在我的应用中锁定方向。在我的应用程序中,我有 UINavigationControllers 具有多个视图,一些视图需要同时支持纵向和横向,而其他视图只需要支持纵向。我怎么能过来这个问题请给我一些想法。

As the ShouldAutorotateToInterfaceOrientation is deprecated in iOS 6 I am not able to lock the orientation in my app. In my app I have UINavigationControllers with multiple views, some views need to support both portrait and landscape, while other views need to support portrait only. How can I over come this problem please suggest me some idea.

谢谢

推荐答案

通过继承UINavigationController锁定方向。

You lock the orientation by subclassing UINavigationController.

这是一个如何做到这一点的绝佳链接。

然后你在你的子类UIViewController中覆盖以下方法来实现锁定(在这种情况下)肖像锁)。

Then you override the following methods in your subclassed UIViewController to achieve the lock (in this case a portrait lock).

-(BOOL)shouldAutorotate
{
    return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

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

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