xcode 启动屏幕中的自定义动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32904309/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:59:17  来源:igfitidea点击:

Custom animation in Launch Screen

iosxcodelaunch-screen

提问by chipbk10

I have created a new project in Xcode 7 using Swift. I noticed that the launch screen is stored in the storyboard file.

我使用 Swift 在 Xcode 7 中创建了一个新项目。我注意到启动屏幕存储在故事板文件中。

So I think if it could be customised by referring it to my CustomLauchScreenViewController. However, when I set the custom class name in LaunchScreen.storyboard, it throws an error:

所以我想是否可以通过将它引用到我的CustomLauchScreenViewController. 但是,当我在 中设置自定义类名时LaunchScreen.storyboard,它会引发错误:

Launch screens may not set custom classnames

启动屏幕可能不会设置自定义类名

So what is the best way to customize the LaunchScreen? I intend to use the LaunchScreen to load some data before launching the main screen.

那么自定义 LaunchScreen 的最佳方法是什么?我打算在启动主屏幕之前使用 LaunchScreen 加载一些数据。

回答by Robert J. Clegg

That's not the purpose of the launch screen. What you can do however if have your first initial viewController 'act' as a launch screen. Just have it display the same image as the launch image and do what you need to do in there. Once you are done, move to your main viewController from there.

这不是启动屏幕的目的。但是,如果您的第一个初始 viewController “充当”启动屏幕,您可以做什么。只需让它显示与启动图像相同的图像,然后在其中执行您需要执行的操作即可。完成后,从那里移动到您的主 viewController。

回答by Sahil Kapoor

The launch screen is shown before your app starts executing in order to provide a transition from the Springboard to your app while it is loading. According to Apple interface guidelines,

启动屏幕在您的应用程序开始执行之前显示,以便在加载时提供从 Springboard 到您的应用程序的过渡。根据苹果界面指南,

A launch file (or image) provides a simple placeholder image that iOS displays when your app starts up. The placeholder image gives users the impression that your app is fast and responsive because it appears instantly and is quickly replaced by the first screen of your app.

启动文件(或图像)提供了一个简单的占位符图像,当您的应用程序启动时,iOS 会显示该图像。占位符图像给用户的印象是您的应用程序快速且响应迅速,因为它会立即出现并很快被应用程序的第一个屏幕取代。

To achieve a transition, remove the class from LaunchScreen.storyboardand set it similar to 0% loading transition. Create a new controller in your Main.storyboardand set CustomLauchScreenViewControllerthere and assign this as initial view controller. Set CustomLauchScreenViewControlleras your root view controller in your app delegate. When launch screen will be replaced by your this controller, transition is too smooth to feel any difference. After loading the data, change your root view controller to required View Controller.

要实现过渡,请移除该类LaunchScreen.storyboard并将其设置为类似于 0% 加载过渡。创建一个新的控制器Main.storyboard并在CustomLauchScreenViewController那里设置并将其分配为初始视图控制器。CustomLauchScreenViewController在您的应用程序委托中设置为您的根视图控制器。当启动屏幕被你的这个控制器取代时,过渡太平滑了,感觉不到任何区别。加载数据后,将根视图控制器更改为所需的视图控制器。