16

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:

enter image description here

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:

  1. I can use Image params to call the gif from my assets.

Image("myAssetsGifName")

  1. 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

  2. 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!

Spencer Reid
  • 409
  • 3
  • 14

1 Answers1

10

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!

enter image description here

Spencer Reid
  • 409
  • 3
  • 14
  • 5
    Sorry for being a newbie in SwiftUI and iOS development. At least, I tried so hard(do research a lot) to solve every problem that I encountered. Idk why someone just consider that my question doesn't show my research effort? Be kind please. – Spencer Reid Jun 02 '20 at 06:52