以横向方式启动应用程序会导致启动时轮换

时间:2010-12-14 06:33:58

标签: cocoa-touch ios rotation orientation launch

我已经实现了shouldAutorotateToInterfaceOrientation,一旦它运行,我的应用程序中的所有内容都可以正常工作。但是我不喜欢我的应用程序在推出时的行为。

当我以纵向方式启动我的应用程序时,它按预期打开,但是当我以横向方向启动我的应用程序时,我看到所有内容都以纵向方向加载(包括状态栏),然后我看到我的屏幕旋转的动画到景观。那个动画很好,但我不希望它在发布时显示。

当我查看大多数其他应用时,他们似乎会在启动时检测到方向,并且在启动时不显示旋转动画(仅当设备在启动时间后旋转)。

如何确保我的应用以正确的方向加载,以便用户在启动时看不到旋转动画。如果用户在启动后旋转设备时只看到旋转动画,我会更喜欢它。

2 个答案:

答案 0 :(得分:5)

好吧,我想我弄明白了。对于从iPhone tempalte创建应用程序然后将其修改为iPad的任何人,您需要在-info.plist文件中添加一行“支持的界面方向”并输入所有支持的方向,如下所示。然后它似乎按预期工作。

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

答案 1 :(得分:0)

我在我的应用中做了类似的事情:

if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeRight){
  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];
}else if ([[UIDevice currentDevice] orientation]==UIInterfaceOrientationLandscapeLeft){
  [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft];
}

简单地说:在开始时检测方向,然后将StatusBarOrientation设置为该值。如果您在重新加载视图之前执行此操作(或至少在应用程序结构中尽可能早地加载视图),则状态栏应从右侧开始显示(因此无需轮换)。 如果你想支持纵向方向,只需为它们添加2个其他分叉......