如何在一开始就检测到iPad的interfaceRotation? [英] How do I detect an iPad's interfaceRotation at the start?

查看:125
本文介绍了如何在一开始就检测到iPad的interfaceRotation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题让我的iPad应用程序在我初始化的第一个UIViewController(代码中)中检测到它的interfaceOrientation。事实上,如果我追踪application.statusBarOrientation,即使我在横向上启动也会返回1(UIInterfaceOrientationPortrait)。

I'm having problems getting my iPad app to detect its interfaceOrientation in the first UIViewController I initialize (in code). In fact, if I trace for application.statusBarOrientation, that too returns 1 (UIInterfaceOrientationPortrait) even if I launched in landscape.

如果我在第一个UIViewController中跟踪self.interfaceOrientation ,它仍然是1,直到它成为viewWillDisappear ...不幸的是太晚了!

If I trace self.interfaceOrientation in my first UIViewController, it remains 1 until it gets to viewWillDisappear... Which is unfortunately too late!

这里有一些代码(即使没有太多可看的):

Here's some code (even though there's not much to see):

在我的appDelegate中我有这个:

In my appDelegate I have this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
     // show loading screen first
     [window addSubview:loadingScreenViewController.view];
     [window makeKeyAndVisible];

     NSLog(@"applicationDidBecomeActive:statusBarOrientation = %d", application.statusBarOrientation);
     return YES;
}

跟踪1(肖像),即使我清楚地看到状态栏是landscape ...在第一个视图控制器中我有这个:

which traces 1 (portrait), even though I clearly see the status bar is landscape... and in the first view controller I have this:

- (void)viewDidLoad
{
    [super viewDidLoad];
     NSLog(@"self.interfaceOrientation = %d", self.interfaceOrientation);
}

即使在横向模式下也会跟踪1。

which also traces 1, even in landscape mode.

任何想法?难倒在这里!

Any ideas? Stumped here!

谢谢:)

: - Joe

推荐答案

这是答案......有点:(来自Apple Dev Forums):....
应用程序始终加载,就像设备是纵向一样,然后如果设备真的是风景,应用程序被告知设备已经旋转。这样做是为了使笔尖和代码只需要在一个方向上创建他们的UI。否则可能需要为每个笔尖设置两个UI布局。 ....这不是我喜欢的答案,但不幸的是iOS的运作方式!

Here is the answer... Somewhat: (from Apple Dev Forums): .... "The app is always loaded as if the device is portrait, and then if the device is really landscape the app is told that the device has rotated. This is done so that nibs and code only need to create their UI in one orientation. Otherwise it might be necessary to have two UI layouts for each nib." .... it's not the answer I'd have liked, but that's how iOS works unfortunately!

这篇关于如何在一开始就检测到iPad的interfaceRotation?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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