一个视图控制器ios的强制横向 [英] Force landscape for one view controller ios

查看:27
本文介绍了一个视图控制器ios的强制横向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了几个类似问题的答案,但没有一个答案有效.我有一个应用程序,除了我拥有的一个照片查看器之外,我需要所有肖像.在目标菜单的支持方向部分中,我只有纵向.我如何强制我的一种观点是风景.它正在从导航控制器推入堆栈,但我正在使用情节提要来控制这一切.

I've looked at several answers to questions similar but none of the answer worked. I have an app where I need everything portait except for one photo viewer I have. In the supported orientations section of the targets menu I only have portrait. How do I force my one view to be landscape. It is being pushed onto the stack from a nav controller but I'm using storyboards to control all that.

推荐答案

由于答案似乎隐藏在问题的评论中,并且由于 ArunMak 的答案相当混乱,所以我将提供我发现的内容:

Since the answer seems to be hidden in the comments of the question and since ArunMak's answer is quite confusing, I'll just offer what I found out:

我所要做的就是将此函数添加到视图的自定义 UIViewController 子类中:

All I had to do was to add this function to my custom UIViewController subclass for the view:

- (NSUInteger)supportedInterfaceOrientations {
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
        // iPad: Allow all orientations
        return UIInterfaceOrientationMaskAll;
    } else {
        // iPhone: Allow only landscape
        return UIInterfaceOrientationMaskLandscape;
    }
}

请注意,该项目需要允许所有方向(即:纵向、左侧横向、右侧横向 - 但在 iPhone 上切勿颠倒!).

Note that the project needs to allow all orientations (that is: Portrait, Landscape Left, Landscape Right - but NEVER Upside Down on an iPhone!).

如果您想将部分或大部分视图限制为 Portrait,则需要在每个视图控制器中实现上述方法(或为其使用公共超类并从其子类化所有其他视图)——如果您限制 DeviceInfo.plist 中的方向只是纵向,应用程序永远不会考虑进入横向.

If you want to limit some or most views to Portrait, you need to implement the above method in every of those view controllers (or use a common super class for it and subclass all others from it) — if you limit the Device Orientation in the Info.plist to just Portrait, the app will never even think of going into landscape.

这篇关于一个视图控制器ios的强制横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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