强制一个视图控制器ios的景观 [英] Force landscape for one view controller ios
问题描述
我已经看过类似问题的几个答案,但答案都没有。我有一个应用程序,我需要一切portait除了我有一个照片查看器。在目标菜单的支持方向部分,我只有肖像。如何强制我的一个视图成为风景。它正从导航控制器推入堆栈,但我正在使用故事板来控制所有这些。
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!).
如果您想将部分或大部分视图限制为纵向,则需要在每个视图控制器中实现上面的方法(或者为它使用一个公共超类,并从中继承所有其他视图控制器) - 如果你将Info.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屋!