横向启动应用程序会导致启动时旋转

发布于 2024-10-07 11:01:17 字数 345 浏览 6 评论 0原文

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

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

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

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

I have implemented shouldAutorotateToInterfaceOrientation and everything works fine in terms or orientation changes in my app once it is running. However I don't like the behavior of my app when it is fist launched.

When I launch my app in portrait orientation, it opens as expected, however when I launch my app in landscape orientation, I see everything load in portrait orientation (including the status bar), then I see an animation of my screen rotating to landscape. That animation is fine, but I don't want it to be displayed at launch.

When I look at most other apps, they seem to detect the orientation as they launch and they do not show the rotation animation on launch (only if the device is rotated after launch time).

How can I make sure my app loads in the proper orientation so the user does not see the rotation animation on launch. I would prefer it if the user only saw the rotation animation if he/she rotates the device after launching.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅浅 2024-10-14 11:01:17

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

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

Okay I think I figured it out. For anybody who created an app from an iPhone tempalte and then modified it for iPad, you need to add a line in your -info.plist file that says "Supported interface orientations" and enter all of the supported orientations as below. Then it seems to work as expected.

    <key>UISupportedInterfaceOrientations</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
    <string>UIInterfaceOrientationLandscapeLeft</string>
    <string>UIInterfaceOrientationLandscapeRight</string>
</array>
乱了心跳 2024-10-14 11:01:17

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

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

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

I have done something like this in my Apps:

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

Simply: detect Orientation at start and then set the StatusBarOrientation to that value. If you do this before you're loading your view (or at least, so earlier like possible within your App Structure), the statusbar should appear from beginning on the right side (so theres no rotation necessary).
If you want to Support also portrait orientation, simply add 2 more else forks for them...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文