【问题标题】:Launching app in landscape orientation causes rotation on launch横向启动应用程序会导致启动时旋转
【发布时间】:2011-05-25 02:31:51
【问题描述】:

我已经实现了 shouldAutorotateToInterfaceOrientation 并且在我的应用程序运行后一切正常或方向变化。但是,我不喜欢我的应用程序首次启动时的行为。

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

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

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

【问题讨论】:

    标签: cocoa-touch ios rotation orientation launch


    【解决方案1】:

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

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

    【讨论】:

    • 优秀。这解决了我遇到的一个问题。我的应用程序仅支持横向,但如果设备不在 UIInterfaceOrientation 设置的方向,则会倒置启动。它会旋转得足够快,但很烦人。 (还必须提供正确的启动图像,因此它有时不会以纵向开始。)谢谢! (对于其他人,这记录在这里j.mp/fY56ml
    • 很高兴能帮上忙!随意投票给我的答案或其他东西,这样我就可以通过回答我自己的问题来获得积分! :)
    【解决方案2】:

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

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

    简单地说:在开始时检测方向,然后将 StatusBarOrientation 设置为该值。如果您在加载视图之前执行此操作(或者至少在您的应用程序结构中尽可能早),状态栏应该从右侧开始出现(因此不需要旋转)。 如果您还想支持纵向,只需为它们添加 2 个 else 叉子...

    【讨论】:

    • 我刚试过这个,但我为 UIInterfaceOrientationPortrait 和 UIInterfaceOrientationPortraitUpsideDown 添加了另外两个 if,它并没有改变任何东西。我的应用程序仍然启动,然后状态栏发生变化,然后屏幕旋转到正确的方向。 :( 我将它添加到我的应用程序委托中的 didFinishLaunchingWithOptions 中。我应该在哪里添加它?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多