只有一个VIEW横向模式 [英] Only ONE VIEW landscape mode

查看:108
本文介绍了只有一个VIEW横向模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完成了我的iOS应用程序,但我只需要将一个视图设置为横向模式,其余视图只能在纵向模式下查看。

I finished my iOS app but I need to set only ONE view to landscape mode, the rest of the views can only be seen in portrait mode.

我'我使用Xcode 5.1并通过从右侧面板中删除我的故事板视图控制器来创建我的所有视图,所以如果你要告诉我在某处写一些代码,请告诉我我需要写的确切位置。

I'm using Xcode 5.1 and I created all of my Views by dropping in my storyboard View Controllers from the right panel, so if you are going to tell me to write some code somewhere, please tell me exactly where I need to write it.

我在这里阅读了一个解决方案 UINavigationController Force Rotate 但是我不知道在哪里写代码。我是否需要手动创建一个 UIViewController

I read one solution here UINavigationController Force Rotate but I don't know where to write that code. Do I need to create one UIViewController manually?

推荐答案

我要去假设你在这里定位iOS 7(使用XCode 5.1,我认为我是对的)。

I am gonna suppose you are targeting iOS 7 here (using XCode 5.1, I think I am right).

首先,你必须明白为了打开一个甚至只有一个视图在景观中超过40种,您的应用程序应该允许横向和纵向界面方向。
默认情况下是这种情况,但您可以在目标设置中进行检查,常规标签,部署信息部分(见下面的截图)。

First, you have to understand that in order to open even just one view out of over 40 in landscape, your app should allow both landscape and portrait interface orientations. It is the case by default, but you can check it in your target's settings, General tab, Deployment Info section (see screenshot below).

然后,因为你允许整个应用程序的横向和纵向,你必须告诉每个只有肖像 UIViewController 它不应该自动旋转,添加此方法的实现:

Then, because you allowed both landscape and portrait for the entire app, you will have to tell every portrait-only UIViewController that it should not autorotate, adding this method's implementation:

- (BOOL)shouldAutorotate {
  return NO;
}

最后,对于您的特定景观控制器,并且因为您说你是以模态方式呈现它,你可以实现这些方法:

Finally, for your specific landscape-only controller, and because you said you are presenting it modally, you can just implement these methods:

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  return UIInterfaceOrientationLandscapeLeft; // or Right of course
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  return UIInterfaceOrientationMaskLandscape;
}

希望这会有所帮助,

这篇关于只有一个VIEW横向模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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