2017-09-06 60 views
0

圖像加載使用SDWebImage GIF,但未能動畫GIF未能動畫在迅速3

override func draw(_ rect: CGRect) { 
    let urlpath:String = Bundle.main.path(forResource: "logo", ofType: "gif")! 
    let url = URL(fileURLWithPath: urlpath) 
    let data = try? Data(contentsOf: url) 
    let image:UIImage = UIImage.sd_animatedGIF(with: data) 
    loaderImage.image = image 

} 

回答

0

如果堅持使用SDWebImage的要求,那麼我要指出,(在library github提到的):

動畫圖片(GIF)支持

  • 從4.0版本開始,我們依靠FLAnimatedImage採取 照顧我們的動畫圖像。

    ...

  • 要使用它,只需確保您使用FLAnimatedImageView,而不是 的UIImageView。

FLAnimatedImage:

對於一個簡單的代碼來斯威夫特使用它,你可以檢查這個answer

0
let url = Bundle.main.url(forResource: "play", withExtension: "gif") 

     DispatchQueue.main.async { 

      self.image.sd_setImage(with: url!) 
     } 

     let imageData = try? Data(contentsOf: Bundle.main.url(forResource: "play", withExtension: "gif")!) 
     let advTimeGif = UIImage.gifImageWithData(imageData!) 
     let imageView2 = UIImageView(image: advTimeGif) 
     imageView2.frame = CGRect(x: 20.0, y: 420.0, width: self.view.frame.size.width - 40, height: 150.0) 
     view.addSubview(imageView2) 

enter image description here