如何检测 iPad 上启动屏幕动画的应用程序启动方向!

How do I detect orientation on app launch for splash screen animation on iPad!(如何检测 iPad 上启动屏幕动画的应用程序启动方向!)

本文介绍了如何检测 iPad 上启动屏幕动画的应用程序启动方向!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个应用程序,我有两个 *.png 用于默认启动画面:

Hi I have an app and I have two *.pngs for default splash screen:

默认横向.pngDefault-Portrait.png

Default-Landscape.png Default-Portrait.png

我想要的是在我的应用程序加载完毕并准备好运行时为这个默认启动屏幕设置动画.

What I want is to animate this default splash screen away when my app is loaded and ready to go.

为了实现这一点,我通常会呈现一个带有默认横向或默认纵向(取决于设备方向)的 UIImageView,将其在屏幕上保留一段时间,然后将其动画化.

To achieve this I would normally present an UIImageView with either default-landscape or default-portrait (depending on the device orientation), keep it on screen for a certain time and then animate it away.

我的问题是,如果我在

My problem is that if I call [[UIDevice currentDevice] orientation] in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

答案始终是设备是纵向的,即使我很清楚它是横向的.我在模拟器和设备上都试过了,行为是一样的.

The answer is always that the device is in portrait orientation even if I clearly have it in landscape. I tried this in simulator and on the device as well and the behaviour is the same.

有没有人知道解决这个问题或其他方法?

Does anyone know a fix for this or maybe some other approach?

谢谢!

推荐答案

我遇到了这个问题,我通过制作一张 1024x1024 的图像并将 UIImageView 的 contentMode 设置为 UIViewContentModeTop,然后使用左右边距自动调整大小来解决它.只要您的纵向和横向默认图像的布局相同,那么这将正常工作.

I had troubles with this and I solved it by making one image 1024x1024 and setting the contentMode of the UIImageView to UIViewContentModeTop, then using left and right margin autoresizing. So long as your portrait and landscape default images are the same layout then this will work fine.

只是为了澄清这是我使用的:

Just to clarify here's what I used:

bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SplashImage]];
bgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
bgView.contentMode = UIViewContentModeTop;

这篇关于如何检测 iPad 上启动屏幕动画的应用程序启动方向!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何检测 iPad 上启动屏幕动画的应用程序启动方向!

基础教程推荐