I want to use the image GIF type which named 'myAssetsGifName', presenting in my project(An App).
For example, I want to reach something just like this GIF:
I did some research before I asking this question.(Link1, Link2, Link3 for Watch OS, Link4 5 years ago...)
However, I didn't find any available solution or example to successfully present the GIF in SwiftUI.
Some of these references or posts are out-of-date. I did try these references's solutions, still not working in SwiftUI. So there are less info can be referenced. I want to reach these goals:
- I can use Image params to call the gif from my assets.
Image("myAssetsGifName")
I can using the url to download the gif and show it(passing that to Image). Just found a possible direction about second issue. Link
If I cannot use Image params to present my GIF from local assets or url downloading. Is there any possible solution could satisfy the needs? (e.g., Using UIViewRepresentable or something else?)
Does anyone know the answer. Which way should I learn from it and using it to reach my goals?
Any help or advice will be greatly appreciated. Thanks a lot!
In order to implement the logo animation we'll need to do two things: Add the first frame of the GIF as a static image in the launch screen. When the app launches add a view in the root view controller that loads the animated GIF at the same spot that we've put the static image in the launch screen.
To turn a Storyboard That storyboard into an animated GIF you simply have to select the “download images” option after you save your storyboard. When you select “download images” you will see “animated GIF” as the fourth option in the menu. Storyboard That will automatically generate the GIF for you.
I just found a possible way to solve this problem(present GIF in my project).
First, you need to know how to use the Cocoapods.
Second, I download this git about GIFView and install its pods. SSSwiftUIGIFView
Third, after installing pods, opening your Xcode project and import like this:
import SSSwiftUIGIFView
Fourth, according to SSSwiftUIGIFView class you should use below code:
SwiftUIGIFPlayerView(gifName: "Your GIF image name here")
Ok, it's done. Now you can use some GIF image in your project or App.
Let's see this finished product!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With