Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to show a *.gif file in a UIImageView in swift

I have a *.gif file that I want to show in a UIImageView. I have tried the library FLAnimatedImage, code below. Result is just a static image.

class LoginVC: UIViewController, UITextFieldDelegate {

    @IBOutlet weak var img_popup: FLAnimatedImageView!

    var img_popupraw: FLAnimatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfFile: "ShitTalk_LoadingAnimation.gif"))

    override func viewDidLoad() {
        img_popup.animatedImage = img_popupraw
    }
}

Open to any alternative ways to show animating gif directly from a gif file. I am using Swift.

like image 564
user1406716 Avatar asked Oct 20 '15 06:10

user1406716


2 Answers

In my case i'm using SDWebImage for manage all image in app. Inclusive have sd_animatedGIFNamed func

install pod 'SDWebImage'

like image 35
jose920405 Avatar answered Sep 20 '22 23:09

jose920405


I strongly recommend you to use SwiftGif.

Import the Gif.swift in your project and do the following:

// Returns an animated UIImage
let jeremyGif = UIImage.gifWithName("jeremy")

// Use the UIImage in your UIImageView
let imageView = UIImageView(image: jeremyGif)
like image 92
Barat Semet Avatar answered Sep 20 '22 23:09

Barat Semet