iOS 启动画面的持续时间 (Default.png)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10007835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS Duration of Splash Screen (Default.png)
提问by 0x90
im using a Default.pngfile for my iPad-app. It appears correctly but i could'nt find a way to modify the duration of the splash screen. Has somebody any suggestions? Google has many sites that show how to setup the startscreen but could'nt find a solution for my problem.
我为我的 iPad 应用程序使用Default.png文件。它显示正确,但我找不到修改启动画面持续时间的方法。有人有什么建议吗?谷歌有很多网站展示了如何设置开始屏幕,但找不到解决我的问题的方法。
回答by Conrad Shultz
The first rule of Human Interface Guidelines for Splash Screensis: don't use splash screens. The second rule is: don't use splash screens!:
启动画面人机界面指南的第一条规则是:不要使用启动画面。第二条规则是:不要使用闪屏!:
Supply a launch image to improve user experience.
Avoid using your launch image as an opportunity to provide:
An “application entry experience,” such as a splash screen
An About window
Branding elements, unless they are a static part of your application's first screen
提供启动图像以改善用户体验。
避免使用您的发布图片作为提供以下内容的机会:
“应用程序入口体验”,例如启动画面
关于窗口
品牌元素,除非它们是应用程序第一个屏幕的静态部分
If you absolutely must include a long-duration splash screen, and have darn good reasons for doing so, the usual approach is to throw up a UIImageView
containing a copy of you launch image in, e.g., application:didFinishLaunchingWithOptions:
- which should provide the illusion of a lengthy splash screen.
如果你绝对必须包含一个长时间的启动画面,并且有充分的理由这样做,通常的方法是抛出一个UIImageView
包含你启动图像的副本,例如application:didFinishLaunchingWithOptions:
- 这应该提供一个冗长的启动画面的错觉屏幕。
But please don't.
但请不要。
回答by Jonas Schnelli
Using a "splash screen" (Logo, etc) is not the idea of the Default.png!
使用“启动画面”(徽标等)不是 Default.png 的想法!
Read the HIGfrom Apple.
阅读Apple的HIG。
The (splash) screen (named loading screen) is not for a Logo showing or something like this. When having multitasking enabled, the "splash screen" shows up really rare. The splash screen should, like the apple apps does, only show the interface coming up in the first application screen without any localized strings, etc.
(闪屏)屏幕(命名为加载屏幕)不是用于显示徽标或类似内容的。启用多任务处理后,“闪屏”很少出现。启动画面应该像苹果应用程序一样,只显示第一个应用程序屏幕中出现的界面,没有任何本地化字符串等。
Also keep in mind: The faster the iOS Device get, the shorter you can see the Default.png. So avoid using it for any important CI/CD content.
还要记住:iOS 设备运行得越快,您看到的 Default.png 就越短。所以避免将它用于任何重要的 CI/CD 内容。
回答by sch
The Default image is displayed while the app is loading and will be dismissed as soon as the app is ready. And there is no API to control that duration.
默认图像在应用加载时显示,并在应用准备好后立即关闭。并且没有 API 来控制该持续时间。
回答by thebarcodeproject
You can't technically modify the duration that the "Default" image stays there; it is designed to just be a temporary image "foreshadowing" the app actually starting up and isn't specifically designed as a splash screen.
从技术上讲,您无法修改“默认”图像停留的持续时间;它被设计为只是一个临时图像,“预示”应用程序实际启动,而不是专门设计为启动画面。
I recommend that you keep the "splash screen effect" by adding an image view to the screen as the app starts in the -application:didFinishLaunchingWithOptions: method. You can then set a timer which calls a method to animate the splash off after the designated time you want it to be. It will be there for a little longer than you specify depending on how long it actually took the app to load up, but it will give the effect you're after.
我建议您通过在 -application:didFinishLaunchingWithOptions: 方法中启动应用程序时向屏幕添加图像视图来保持“启动画面效果”。然后,您可以设置一个计时器,它会在您希望的指定时间之后调用一个方法来为飞溅设置动画。它将在那里的时间比您指定的时间长一点,具体取决于应用程序实际加载的时间,但它会产生您想要的效果。
You can set the image view's image to [UIImage imageNamed:@"Default"] and it will access that Default artwork for you.
您可以将图像视图的图像设置为 [UIImage imageNamed:@"Default"],它会为您访问该默认图稿。
回答by Konrad77
You can't change the duration. If you want it be shown longer though, you can add the same image to a view that you show while you're loading your data!
您无法更改持续时间。但是,如果您希望它显示更长时间,您可以将相同的图像添加到加载数据时显示的视图中!
回答by asgeo1
There is a good blog post here on how to create a splash screen using a UIImageView
with a timer:
这里有一篇很好的博客文章,介绍了如何使用UIImageView
带定时器的创建启动画面:
http://nullpointr.wordpress.com/2012/02/19/iphone-dev-how-to-implement-a-splash-screen/
http://nullpointr.wordpress.com/2012/02/19/iphone-dev-how-to-implement-a-splash-screen/
Useful for beginners, who are still learning the best way to do things in iOS.
对初学者有用,他们仍在学习在 iOS 中做事的最佳方式。
回答by OhadM
As @Conrad Shultz answered, splash screen should be used only via the supplied LaunchScreen.storyboard
file by Xcode.
正如@Conrad Shultz 所回答的,启动画面只能通过LaunchScreen.storyboard
Xcode提供的文件使用。
However, in rare situations you do want to prolong the splash screen:
但是,在极少数情况下,您确实希望延长启动画面:
- Download A LOT of files before the app starts since the app depends on them.
- Other reason...
- 在应用程序启动之前下载大量文件,因为应用程序依赖于它们。
- 其他原因...
This is the way to do it:
这是这样做的方法:
Inside AppDelegate
, under didFinishLaunchingWithOptions
you should:
在里面AppDelegate
,didFinishLaunchingWithOptions
你应该:
- Create a VC that has the samesplash image and the sameconstraints
- Present it
- Dismiss it after a given time
- 创建一个具有相同初始图像和相同约束的 VC
- 呈现它
- 在给定时间后关闭它
The code:
编码:
let splashVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "splash")
window?.makeKeyAndVisible()
if let root = window?.rootViewController
{
root.present(splashVC, animated: false, completion: nil)
let dispatchTime = DispatchTime.now() + 3
// didFinishLaunchingWithOptions will return and this block will be executed afterwards, hence, async..
DispatchQueue.main.asyncAfter(deadline: dispatchTime, execute: {
root.presentedViewController?.dismiss(animated: false, completion: nil)
})
}
}