[英]Add a Launch Screen to the iOS App in Code in Swift (without Storyboard or Launchboard)
I created my views in code. 我在代码中创建了我的视图。 The starting point is the didFinishLaunchWithOptions function in the Appdelegate class. 起点是Appdelegate类中的didFinishLaunchWithOptions函数。
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let controller = ViewController() // create an instance of my ViewController and set it to the rootViewController
window?.rootViewController = controller
I would like to add a launch screen that appears instantly when your app starts up. 我想添加一个在您的应用启动时立即显示的启动屏幕。 The launch screen should be quickly replaced with the first screen of the app, giving the impression that your app is fast and responsive. 应该使用应用的第一个屏幕快速替换启动屏幕,从而给人以您的应用快速响应的印象。 I found some answers that said it is not possible( Is there any way to code the LaunchScreen programmatically ). 我发现一些答案说它不可能( 有没有办法以编程方式编写LaunchScreen代码 )。 My idea was creating a new launchView and replace it through NSTimer. 我的想法是创建一个新的launchView并通过NSTimer替换它。 Isn't there any easier or alternative way ? 有没有更简单或替代的方式?
Thanks 谢谢
This is not possible as such as the Launch Screen is not a regular View Controller and it cannot hold any logic. 这是不可能的,因为启动屏幕不是常规的视图控制器,它不能保持任何逻辑。 Any animations which are there in the App during startup are handled after the launch Screen has appeared and the animations are in the root view controller as in Twitter app. 启动期间应用程序中存在的任何动画都会在启动屏幕出现后处理,并且动画在Twitter应用程序中位于根视图控制器中。 If you are completely against using launch Screens then an alternative would be make a view in IB and use its screenShot as a splashImage. 如果你完全反对使用启动屏幕,那么另一种方法是在IB中创建一个视图并将其screenShot用作splashImage。 There is no way as of now to make a launchScreen programatically or to add any logic to it. 到目前为止,无法以编程方式创建launchScreen或向其添加任何逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.