获取iPad应用的发布方向 [英] Get launch orientation of iPad app

查看:87
本文介绍了获取iPad应用的发布方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的iPad应用程序中,我需要运行一些布局代码,以根据方向设置正确的布局。默认情况下,布局被配置为横向,因此在应用程序以纵向模式启动的情况下,我需要采取额外的操作来正确配置视图以便纵向显示。

In my iPad app, I need to run some layout code to set the proper layout depending on the orientation. By default, the layout is configured for the landscape orientation, so in the case that the app starts in portrait mode, I need to take extra action to configure the views properly for display in portrait.

-application:didFinishLaunchingWithOptions:方法中,我使用 [[UIDevice currentDevice] orientation]检查方向。这里的问题是,它总是返回纵向,即使应用程序是从景观开始。有什么办法吗?

In my -application:didFinishLaunchingWithOptions: method, I check the orientation using [[UIDevice currentDevice] orientation]. The problem here is that it always returns portrait even if the app is starting in landscape. Is there any way around this?

推荐答案

这是预期的行为。 Quoth UIViewController文档

This is expected behavior. Quoth the UIViewController documentation:


注意:在启动时,应用程序应始终以纵向方向设置其界面。在应用程序:didFinishLaunchingWithOptions:方法返回后,应用程序使用上述视图控制器旋转机制,在显示窗口之前将视图旋转到适当的方向。

Note: At launch time, applications should always set up their interface in a portrait orientation. After the application:didFinishLaunchingWithOptions: method returns, the application uses the view controller rotation mechanism described above to rotate the views to the appropriate orientation prior to showing the window.

换句话说,就设备而言,在应用程序启动时,方向纵向。在应用程序:didFinishLaunchingWithOptions:之后的某个时刻,它会检测不同的方向并调用 shouldAutorotateToInterfaceOrientation: a href =http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW58>其他视图旋转方法,您应该照常处理。

In other words, as far as the device is concerned the orientation is portrait while the application is launching. At some point after application:didFinishLaunchingWithOptions: it will detect the different orientation and call your shouldAutorotateToInterfaceOrientation: method and then your other view rotation methods, which you should handle as normal.

这篇关于获取iPad应用的发布方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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