如何检测 iPad 上启动屏幕动画的应用程序启动方向!
您好,我有一个应用程序,并且有两个用于默认启动屏幕的 *.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
要在开始时了解方向是什么(
UIDevice
方向在用户旋转设备之前不起作用),请拦截视图控制器的shouldAutorotateToInterfaceOrientation
,它在开始时被调用,并且您知道您的设备方向。To know at start what is the orientation (
UIDevice
orientation don't work until user have rotate the device) interceptshouldAutorotateToInterfaceOrientation
of your View Controller, it is called at start, and you know your device orientation.有时,您希望在用户控制您的应用程序之前从加载图像转换为其他内容。除非您的应用程序非常简单,否则从加载图像到登录页面可能还不够,而不会让应用程序体验变得非常糟糕。如果您曾经开发过大型应用程序,那么您肯定会希望在设置、加载 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.
操作系统仅旋转添加到窗口的第一个视图。因此,如果您希望启动屏幕自动旋转并且您的主视图是可旋转的,那么只需将其添加为该视图的子视图即可。
以下是我用于淡出相应启动屏幕图像的代码:
注意:您必须更新它才能支持高分辨率屏幕。
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:
Note: You'll have to update it to support hi-res screens.
听起来您没有按照 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 :)
我遇到了这个问题,我通过将一张图像设置为 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:
为了解决这个问题,我在允许两个方向的视图控制器内安装了启动图像视图。尽管设备在启动时报告了错误的方向,但视图控制器似乎得到了正确的方向。
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.
您可以按如下方式使用 UIApplication statusBarOrientation:
You can use UIApplication statusBarOrientation as follows:
也许您可以在开始时显示一个带有黑色背景的空白视图,并将
[[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'sviewDidAppear
and start your splash screen from there?另一种解决方案是读取加速度计数据并自行确定方向。
Another solution would be to read the accelerometer data and determine the orientation yourself.