Sample or demo SWIFT code using FLAnimatedImage

I am trying to incorporate FLAnimatedImage into my Swift based iOS application to display an animated GIF.

I started importing the files FLAnimatedImage.h and FLAnimatedImageView.m and created Bridging-Header.h without any problems.

I tried loading Gif into my ImageView using this code:

 @IBOutlet weak var animatedImageView: FLAnimatedImageView! = animatedImageView.animatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfFile: "chicken.gif")) ` 

But it does not work when starting the application with the following error code:

exception 'NSInvalidArgumentException', reason: '- [UIImageView setAnimatedImage:]: unrecognized selector sent to instance 0x78e3c820'

Any suggestion on how to fix the above error?

Thanks for any help.

+5
source share
2 answers
 import UIKit class ViewController: UIViewController { @IBOutlet weak var gifView: FLAnimatedImageView! override func viewDidLoad() { super.viewDidLoad() print("\(gifView)") if let path = NSBundle.mainBundle().pathForResource("rock", ofType: "gif") { if let data = NSData(contentsOfFile: path) { let gif = FLAnimatedImage(animatedGIFData: data) gifView.animatedImage = gif } } } } 

By the way, did you make your animatedImageView in the storyboard subclassed from FLAnimatedImageView?

+6
source

I got it to work with the following extension:

 extension FLAnimatedImage { convenience init(gifResource: String) { self.init(animatedGIFData: NSData(contentsOfFile: NSBundle.mainBundle().pathForResource(gifResource, ofType: "")!)) } } 


declarations:

 @IBOutlet weak var animatedImageView: FLAnimatedImageView! 


Call:

 animatedImageView.animatedImage = FLAnimatedImage(gifResource: "chicken.gif") 

And in the storyboard, UIImageView has its own subclass: FLAnimatedImageView

-1
source

Source: https://habr.com/ru/post/1234032/


All Articles