Swift 3:在UIWebView中加载GIF

Ne *_* AS 0 gif uiwebview ios swift

我想在我的swift 3应用程序中加载GIF.我使用这段代码来做到这一点,但没有显示gif.

let filePath = Bundle.main.path(forResource: “myGif”, ofType: "gif")
let gif = NSData(contentsOfFile: filePath!)
self.webView.load(gif! as Data, mimeType: "image/gif", textEncodingName: String(), baseURL: NSURL() as URL)
self.webView.isUserInteractionEnabled = false
Run Code Online (Sandbox Code Playgroud)

我不知道我的代码有什么问题(我是swift和iOS开发的新手).

有什么帮助吗?

mik*_*sis 5

我从github 找到了SwiftGif Lbrary,它没有使用webview(如果你想用webview写我评论来更新答案)

编辑:

网页流量:

let url = Bundle.main.url(forResource: "source", withExtension: "gif")!
let data = try! Data(contentsOf: url)
webview.load(data, mimeType: "image/gif", textEncodingName: "UTF-8", baseURL: NSURL() as URL)
webview.scalesPageToFit = true
webview.contentMode = UIViewContentMode.scaleAspectFit
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你.