如何在 xcode 故事板中以横向模式显示场景?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9001106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:05:57  来源:igfitidea点击:

How to show scene in landscape mode within xcode storyboard?

iphonexcodeuiwebviewlandscape-portraitxcode-storyboard

提问by jcamacho

I have storyboard project in xcode. Most scene is show in portrait orientation but I want to show one of scene in landscape mode without user rotate the device, always this scene is shown it must be in landscape. This scene has a simple viewcontroller with uiwebview object wich I open a pdf file from url. My idea is show the viewcontroller as a modal viewcontroller.

我在 xcode 中有故事板项目。大多数场景都以纵向显示,但我想在没有用户旋转设备的情况下以横向模式显示其中一个场景,始终显示此场景必须以横向方式显示。这个场景有一个带有 uiwebview 对象的简单视图控制器,我从 url 打开了一个 pdf 文件。我的想法是将视图控制器显示为模态视图控制器。

Anyone known how solve this issue?, yesterday I spend my time searching about this in Internet but I don't find out a solution.

有人知道如何解决这个问题吗?,昨天我花时间在互联网上搜索这个问题,但我没有找到解决方案。

Thank you in advance!

先感谢您!

回答by Dennis Bliefernicht

How the scene is actually displayed is not determined by the storyboard but rather the viewcontroller. You need to create an UIViewControllersubclass and implement - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationto return YESonly if the interface orientation is a landscape orientation. You could do it like this:

场景的实际显示方式不是由情节提要决定的,而是由视图控制器决定的。您需要创建一个UIViewController子类并实现仅当界面方向为横向时才- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation返回YES。你可以这样做:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

to allow both orientations or replace with

允许两个方向或替换为

return interfaceOrientation == UIInterfaceOrientationLandscapeLeft

to allow only one direction.

只允许一个方向。