【问题标题】:TVOS: Unable to display a GIF with GIFU frameworkTVOS:无法使用 GIFU 框架显示 GIF
【发布时间】:2021-02-25 13:07:29
【问题描述】:

我正在关注这个tutorial: 一开始,我没有显示 gif,而是显示一个红色的 UIView 方块,只是为了测试:

通过使用此代码:

import Gifu
import TinyConstraints

class GifViewController: UIViewController {
   
     lazy var loadingGif: UIView = {
         let view = UIView()
         view.backgroundColor = .red
         return view
     }()
 
   override func viewDidLoad() {
          super.viewDidLoad()
          setupViews()
      }
    fileprivate func setupViews(){
        view.backgroundColor = .blue
        view.addSubview(loadingGif)
        loadingGif.centerInSuperview()
        loadingGif.width(300)
        loadingGif.height(300)
     
    }
}

在我添加 Gif 代码替换红色方块 UIVIEW 之后:

import Gifu
import TinyConstraints

class GifViewController: UIViewController {
    /*
     lazy var loadingGif: UIView = {
         let view = UIView()
         view.backgroundColor = .red
         return view
     }()
     **/

    lazy var loadingGif: GIFImageView = {
        let view = GIFImageView()
        view.contentMode = .scaleAspectFit
        view.animate(withGIFNamed: "loading")
        return view
    }()
   override func viewDidLoad() {
          super.viewDidLoad()
          setupViews()
      }
    fileprivate func setupViews(){
        view.backgroundColor = .blue
        view.addSubview(loadingGif)
        loadingGif.centerInSuperview()
        loadingGif.width(300)
        loadingGif.height(300)
     
    }
}

这是结果:
如您所见,什么都没有出现,我不知道为什么。
这是存储在资产中的“loading.gif”:
我尝试使用不同的 GIF,但仍然没有出现。
关于为什么没有出现的任何提示?

【问题讨论】:

    标签: ios swift uiimageview gif tvos


    【解决方案1】:

    我使用了另一个库,它就像一个魅力:

    import SwiftGifOrigin
    
    class GifViewController: UIViewController {
      
        lazy var loadingGif: UIImageView = {
            let view = UIImageView()
            view.loadGif(asset: "cvs_loader")
            view.contentMode = .scaleAspectFit
            return view
        }()
        
        override func viewDidLoad() {
            super.viewDidLoad()
            setupViews()
        }
        fileprivate func setupViews(){
            view.backgroundColor = .blue
            view.addSubview(loadingGif)
            loadingGif.centerInSuperview()
            loadingGif.width(175)
            loadingGif.height(300)
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-14
      • 2016-05-21
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 2011-03-11
      相关资源
      最近更新 更多