使用FLAnimatedImage的示例或演示SWIFT代码 [英] Sample or Demo SWIFT code using FLAnimatedImage

查看:448
本文介绍了使用FLAnimatedImage的示例或演示SWIFT代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图在基于Swift的iOS应用程序中加入FLAnimatedImage,以显示动画GIF.

I'm trying to incorporate FLAnimatedImage in my Swift-based iOS application for the purposes of displaying an animated GIF.

我开始导入FLAnimatedImage.hFLAnimatedImageView.m文件,并成功创建了Bridging-Header.h.

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

我尝试使用以下代码将Gif加载到我的ImageView中:

I tried to load the Gif into my ImageView with this code:

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

但是在应用程序启动时失败,并显示以下错误代码:

But it fails at application startup with the following error code:

异常'NSInvalidArgumentException',原因:'-[UIImageView setAnimatedImage:]:无法识别的选择器已发送到实例0x78e3c820'

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

关于如何解决上述错误的任何建议?

Any suggestion on how to fix the above error?

感谢您的帮助.

推荐答案

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子类化的情节提要中创建了animatedImageView?

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

这篇关于使用FLAnimatedImage的示例或演示SWIFT代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆