美文网首页
iOS加载gif动态背景

iOS加载gif动态背景

作者: 有虫吃 | 来源:发表于2019-03-05 10:45 被阅读0次

    官方没有直接加载gif动态图的控件,目前将gif文件转为Data类型,通过
    WKWebView加载Data类型数据,具体代码如下:

           let webConfiguration = WKWebViewConfiguration()
            webConfiguration.allowsInlineMediaPlayback = true
            webConfiguration.allowsAirPlayForMediaPlayback = true
            let webView = WKWebView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: view.frame.size.height), configuration: webConfiguration)
            self.view.addSubview(webView)
            let filePath = Bundle.main.path(forResource: "4", ofType: "gif")
            let gif = NSData(contentsOfFile: filePath!)! as Data
            webView.load(gif, mimeType: "image/gif", characterEncodingName: "", baseURL: URL.init(fileURLWithPath: filePath!))
    

    相关文章

      网友评论

          本文标题:iOS加载gif动态背景

          本文链接:https://www.haomeiwen.com/subject/pkkwuqtx.html