简体   繁体   English

如何让我的iPhone应用程序以横向模式启动?

[英]How do I get my iPhone app to start in Landscape mode?

My app is fixed to landscape mode, yet during viewDidLoad() and even viewWillAppear(), the following portrait dimensions still return: 我的应用程序已修复为横向模式,但在viewDidLoad()甚至viewWillAppear()期间,以下纵向尺寸仍会返回:

self.view.bounds.size.width = 320.00
self.view.bounds.size.height = 480.00

It's not until viewDidAppear() that the actual landscape dimensions result. 直到viewDidAppear()才产生实际的景观尺寸。

self.view.bounds.size.width = 480.00
self.view.bounds.size.height = 320.00

I find this weird. 我发现这很奇怪。 Why does this happen!? 为什么会这样?!? and how can I fix this? 我该如何解决这个问题?

In your app's info.plist file, specify the key: 在应用程序的info.plist文件中,指定密钥:

 UISupportedInterfaceOrientations

with values for landscape left and right: 左,右景观值:

在此输入图像描述

EDIT : 编辑

The raw plist code should look like this: 原始plist代码应如下所示:

    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>

Edit 2 编辑2

You also need this key which determines the initial orientation of the status bar: 您还需要此键来确定状态栏的初始方向:

 <key>UIInterfaceOrientation</key>
 <string>UIInterfaceOrientationLandscapeRight</string>

Further, you need to make sure that ALL of your view controllers (tabbar, navbar, regular view-controllers) implement 此外,您需要确保所有视图控制器(标签栏,导航栏,常规视图控制器)实现

 shouldAutorotateToInterfaceOrientation

and return a Landscape (left or right) value. 并返回风景(左或右)值。

Here is an Apple docs article on the subject: 这是有关该主题的Apple文档文章:

Technical Note TN2244 技术说明TN2244

And finally, here are some other SO posts on this topic: post 1 and post 2. 最后,这是有关此主题的其他一些SO帖子: 帖子1帖子2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iPhone,如何强制一个视图进入横向模式? - iPhone, How do I force one view into landscape mode? 在iPhone的纵向和横向模式下保持我的应用布局 - Keeping my app's layouts on portrait and landscape mode in iPhone 如何将我的应用限制为横向模式? - How to restrict my app to landscape mode? 我希望我的应用程序以纵向启动,但希望第二个视图以横向启动,我该如何做? - I want my application to start in portrait, but want a second view to start in landscape, how do I do this? 如何仅在iPhone的横向模式(视口metatag)中定义网站的宽度? - How do I define website's width only in iPhone's landscape mode (viewport metatag)? 如何通过JavaScript检测iPhone何时进入横向模式?有这样的事件吗? - How do I detect when the iPhone goes into landscape mode via JavaScript? Is there an event for this? 如何在iPhone中为横向编码? - How do I code for the landscape orientation in iPhone? 如何在iPhone中为横向编码? - How do I code for the landscape orientation in iPhone? 仅在横向模式下启动应用程序,然后在横向模式下锁定应用程序 - Start app in landscape mode only and lock the application in landscape mode 如何在iPhone上测试我的应用 - How do I test my app on iphone
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM