简体   繁体   English

LaunchScreen.storyboard和SwiftGif

[英]LaunchScreen.storyboard & SwiftGif

I found a gif I would like to play on my LaunchScreen.storyboard, and since my research supported that Swift 4 didn't natively support playing gifs, I found a CocoaPod named SwiftGif that auto-plays gifs in a UIImageView. 我在LaunchScreen.storyboard上找到了想播放的gif图像,并且由于我的研究支持Swift 4本身不支持播放gif图像,所以我找到了一个名为SwiftGif的CocoaPod ,它可以在UIImageView中自动播放gif图像。 With SwiftGif, you have to programmatically assign the gif to the UIImageView. 使用SwiftGif,您必须以编程方式将gif分配给UIImageView。

let jeremyGif = UIImage.gif(name: "jeremy")

If you just select the gif from the dropdown of images in the Storyboard, it won't play. 如果您只是从情节提要中的图像下拉列表中选择gif,它将无法播放。 The problem is that I can't give the LaunchScreen.storyboard file (or a view inside of it) a custom class, or I will get this error . 问题是我无法为LaunchScreen.storyboard文件(或其中的视图)提供自定义类,否则我将得到此错误 What can I do? 我能做什么?

I'm using Xcode 9.2, Swift 4, MacBook Pro (13-inch, 2017, Four Thunderbolt 3 Ports), and macOS High Sierra 10.13.2. 我正在使用Xcode 9.2,Swift 4,MacBook Pro(13英寸,2017年,四个Thunderbolt 3端口)和macOS High Sierra 10.13.2。

Thank you! 谢谢!

Unfortunately the launch screen only allows for static images to be placed. 不幸的是,启动屏幕仅允许放置静态图像。 Animations or custom code is not allowed. 不允许使用动画或自定义代码。 However, you can make the feeling of an animated launch screen by presenting a view with the same image and position as the launch screen and animating the view right after launch. 但是,您可以通过呈现与启动屏幕相同的图像和位置的视图,并在启动后立即对视图进行动画处理,来感受动画启动屏幕的感觉。

In order to implement a GIF animation on the launch screen, you'll need to do two things: 为了在启动屏幕上实现GIF动画,您需要做两件事:

  1. Add the first frame of the GIF as a static image in the launch screen 在启动屏幕中将GIF的第一帧添加为静态图像
  2. When the app launches add a view in the root view controller that loads the animated GIF at the same spot that you've put the static image in the launch screen 当应用启动时,在根视图控制器中添加一个视图,该视图将动画GIF加载到将静态图像放入启动屏幕的同一位置

This way, when the app launches the user will get the impression that the launch screen is animating. 这样,当应用启动时,用户将获得启动屏幕正在动画的印象。
You can read a detailed explanation on how to do it on this blog post . 您可以在此博客文章中阅读有关如何执行操作的详细说明。
I've also set up an example project on GitHub that shows how to implement it using the SwiftyGif pod that you used. 我还在GitHub上建立了一个示例项目 ,展示了如何使用您使用的SwiftyGif pod实现它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM