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

发布于 2024-09-13 21:19:52 字数 531 浏览 5 评论 0原文

您好,我有一个应用程序,并且有两个用于默认启动屏幕的 *.png:

Default-Landscape.png Default-Portrait.png

我想要的是在我的应用程序加载并准备就绪时以动画方式关闭此默认启动屏幕。

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

我的问题是,如果我在

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

答案中调用 [[UIDevice currentDevice]orientation] ,则设备始终处于纵向方向,即使我显然将其横向放置。我在模拟器和设备上尝试过此操作,行为是相同的。

有谁知道这个问题的解决方法或者其他方法?

谢谢!

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

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.

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?

Thanks!

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

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

发布评论

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

评论(9

鸠书 2024-09-20 21:19:53

要在开始时了解方向是什么(UIDevice 方向在用户旋转设备之前不起作用),请拦截视图控制器的 shouldAutorotateToInterfaceOrientation,它在开始时被调用,并且您知道您的设备方向。

To know at start what is the orientation (UIDevice orientation don't work until user have rotate the device) intercept shouldAutorotateToInterfaceOrientation of your View Controller, it is called at start, and you know your device orientation.

我不在是我 2024-09-20 21:19:53

有时,您希望在用户控制您的应用程序之前从加载图像转换为其他内容。除非您的应用程序非常简单,否则从加载图像到登录页面可能还不够,而不会让应用程序体验变得非常糟糕。如果您曾经开发过大型应用程序,那么您肯定会希望在设置、加载 xib 等过程中显示进度。如果应用程序需要几秒钟的时间来准备而没有反馈,用户会讨厌它。 IMO,良好的过渡效果也没有什么问题。几乎没有人按照苹果建议的方式使用加载屏幕。我不知道您看过哪些应用程序显示了他们建议的“空 UI”类型加载屏幕。哎呀,即使是苹果公司也不会这样做,除非在他们的示例代码中,而且我的客户都不会认为这是可以接受的。这是一个蹩脚的设计。

There are certainly times when you want to transition from the loading image to something else before the user gets control of your app. Unless your app is really simple, going from loading image to landing page probably won't be sufficient without making the app experience really suck. If you ever develop a large app, you'll definitely want to do that to show progress during setup, loading xibs, etc. If an app takes several seconds to prepare with no feedback, users will hate it. IMO, there's nothing wrong with a nice transition effect either. Almost nobody uses loading screens the way Apple suggests to. I don't know which apps you looked at that showed the "empty UI" type loading screens they suggest. Heck, even Apple doesn't do that except in their sample code and none of my clients would find that acceptable. It's a lame design.

合久必婚 2024-09-20 21:19:53

操作系统仅旋转添加到窗口的第一个视图。因此,如果您希望启动屏幕自动旋转并且您的主视图是可旋转的,那么只需将其添加为该视图的子视图即可。

以下是我用于淡出相应启动屏幕图像的代码:

    // Determine which launch image file
NSString * launchImageName = @"Default.png";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
        launchImageName = @"Default-Portrait.png";
    } else {
        launchImageName = @"Default-Landscape.png";
    }
}

// Create a fade out effect
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.window.frame] autorelease];
whiteoutView.autoresizingMask = UIViewAutoresizingFlexibleWidth  | UIViewAutoresizingFlexibleHeight;
whiteoutView.autoresizesSubviews = YES;         
whiteoutView.image = [UIImage imageNamed:launchImageName];
[[[self.window subviews] objectAtIndex:0] addSubview:whiteoutView];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];

注意:您必须更新它才能支持高分辨率屏幕。

Only the first view added to the window is rotated by the OS. So if you want your splash screen to automatically rotate AND your main view is rotatable then just add it as a child of that view.

Here is my code for fading out the appropriate splash screen image:

    // Determine which launch image file
NSString * launchImageName = @"Default.png";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
        launchImageName = @"Default-Portrait.png";
    } else {
        launchImageName = @"Default-Landscape.png";
    }
}

// Create a fade out effect
UIImageView* whiteoutView = [[[UIImageView alloc] initWithFrame:self.window.frame] autorelease];
whiteoutView.autoresizingMask = UIViewAutoresizingFlexibleWidth  | UIViewAutoresizingFlexibleHeight;
whiteoutView.autoresizesSubviews = YES;         
whiteoutView.image = [UIImage imageNamed:launchImageName];
[[[self.window subviews] objectAtIndex:0] addSubview:whiteoutView];

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
whiteoutView.alpha = 0.0;
[UIView commitAnimations];

Note: You'll have to update it to support hi-res screens.

凌乱心跳 2024-09-20 21:19:53

听起来您没有按照 Apple 在 iOS HIG。它特别指出您不应将其用作启动屏幕,而应将其用作实际 UI 的骨架版本。最终效果是您的应用程序似乎准备得更快。

在 viewDidAppear 或类似应用程序启动后您可以自己绘制启动屏幕的建议也缺少启动图像的基本用途。这不是闪屏。如果您的应用程序已准备就绪,请让用户与其交互,不要浪费时间绘制启动屏幕。

从我对 Apple 应用程序和第三方应用程序的五分钟调查来看,每个人都显示了纵向启动图像,加载了 UI 的纵向版本,然后旋转为横向。自从在 iOS 上编程以来已经有一段时间了,但我认为这反映了方法调用的顺序——首先启动你的应用程序,然后它被告知旋转到特定方向。

不过,向 Apple 提交增强请求可能是一个不错的选择:)

It sounds like you're not using the launch image the way Apple recommends in the iOS HIG. It specifically calls out that you should not use it as a splash screen, but rather as a skeleton version of your actual UI. The net effect is that your app appears to be ready just that much faster.

The suggestions that you could draw a splash screen yourself after the app has launching in viewDidAppear or similar also are missing the basic purpose of a launch image. It's not a splash screen. If your app is ready, let the user interact with it, don't waste their time drawing a splash screen.

From my five minute survey of Apple apps and third-party apps, everyone showed a portrait launch image, loaded the portrait version of the UI, and then rotated to landscape. It's been a while since programming on iOS, but I think this mirrors the order of the method calls -- first your app gets launched, then it is told to rotate to a particular orientation.

It might be a nice enhancement request to file with Apple though :)

初熏 2024-09-20 21:19:52

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

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

bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:SplashImage]];
bgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
bgView.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;
壹場煙雨 2024-09-20 21:19:52

为了解决这个问题,我在允许两个方向的视图控制器内安装了启动图像视图。尽管设备在启动时报告了错误的方向,但视图控制器似乎得到了正确的方向。

To get around this problem I installed the splash image view inside of a view controller that allowed both orientations. Even though the device reported the wrong orientation at startup, the view controller seems to get the right one.

还在原地等你 2024-09-20 21:19:52

您可以按如下方式使用 UIApplication statusBarOrientation:

if ( UIDeviceOrientationIsLandscape( [[UIApplication sharedApplication] statusBarOrientation] ))
    {
    // landscape code
    }
else
    {
    // portrait code
    }

You can use UIApplication statusBarOrientation as follows:

if ( UIDeviceOrientationIsLandscape( [[UIApplication sharedApplication] statusBarOrientation] ))
    {
    // landscape code
    }
else
    {
    // portrait code
    }
盗梦空间 2024-09-20 21:19:52

也许您可以在开始时显示一个带有黑色背景的空白视图,并将 [[UIDevice currentDevice]orientation] 放入该视图的 viewDidAppear 中,然后从那里启动启动屏幕?

Maybe you could show a blank view with black background at start time and place [[UIDevice currentDevice] orientation] into this view's viewDidAppear and start your splash screen from there?

酒绊 2024-09-20 21:19:52

另一种解决方案是读取加速度计数据并自行确定方向。

Another solution would be to read the accelerometer data and determine the orientation yourself.

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