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

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

问题描述

为了显示动画 GIF,我正在尝试将 FLAnimatedImage 合并到基于 Swift 的 iOS 应用程序中.

我开始导入 FLAnimatedImage.hFLAnimatedImageView.m 文件并创建了 Bridging-Header.h 没有问题.>

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

@IBOutlet 弱变种动画图像视图:FLAnimatedImageView!= animationImageView.animatedImage = FLAnimatedImage(animatedGIFData: NSData(contentsOfFile: "chicken.gif")) `

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

<块引用>

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

关于如何修复上述错误的任何建议?

感谢您的帮助.

解决方案

import UIKit类视图控制器:UIViewController {@IBOutlet 弱变量 gifView:FLAnimatedImageView!覆盖 func viewDidLoad() {super.viewDidLoad()打印(\(gifView)")if let path = NSBundle.mainBundle().pathForResource("rock", ofType: "gif") {如果让数据 = NSData(contentsOfFile: path) {让 gif = FLAnimatedImage(animatedGIFData: 数据)gifView.animatedImage = gif}}}}

顺便说一下,您是否在从 FLAnimatedImageView 子类化的故事板中制作了 animatedImageView?

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

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

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:

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

Any suggestion on how to fix the above error?

Thanks for any help.

解决方案

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?

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

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