使用FLAnimatedImage的示例或演示SWIFT代码
我正在尝试将FLAnimatedImage整合到基于Swift的iOS应用程序中,以显示animationGIF。
我开始导入FLAnimatedImage.h
和FLAnimatedImageView.m
文件,并创build了Bridging-Header.h
。
我试图用这个代码加载到我的ImageView的Gif:
@IBOutlet weak var animatedImageView: FLAnimatedImageView! = animatedImageView.animatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfFile: "chicken.gif")) `
但它在应用程序启动时失败,出现以下错误代码:
exception'NSInvalidArgumentException',原因:' – [UIImageView setAnimatedImage:]:无法识别的select发送到实例0x78e3c820'
有关如何解决上述错误的任何build议?
谢谢你的帮助。
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 } } } }
顺便说一下,你是否在FLAnimatedImageView的子类别中创build了animatedImageView
图片视图?
我得到它与以下扩展工作:
extension FLAnimatedImage { convenience init(gifResource: String) { self.init(animatedGIFData: NSData(contentsOfFile: NSBundle.mainBundle().pathForResource(gifResource, ofType: "")!)) } }
宣言:
@IBOutlet weak var animatedImageView: FLAnimatedImageView!
呼叫:
animatedImageView.animatedImage = FLAnimatedImage(gifResource: "chicken.gif")
在故事板中,UIImageView有一个自定义的子类: FLAnimatedImageView