ios - UIWebView 中的动图

标签 ios xcode swift uiwebview ios8

var filePath = NSBundle.mainBundle().pathForResource("long1", ofType: "gif")
var gif = NSData(contentsOfFile: filePath!)     
var webViewBG = UIWebView(frame: view.frame)
webViewBG.loadData(gif, MIMEType: "image/gif", textEncodingName: nil, baseURL: nil)
webViewBG.userInteractionEnabled = false
self.view.insertSubview(webViewBG, atIndex: 0)

这是我添加一个加载了 Gif 的 webview 的代码。但是,虽然 web View 可能会填充 view.frame,但 .gif 不会填充 web View 。因此,gif 周围有灰色边框。

我试过 sizetoscale 和其他各种技巧,但都没有用!

编辑

UIImage+animatedGIF效果很好

最佳答案

您是否只是因为需要显示 gif 而使用 webview?因为您也可以显示 gif。使用UIImage+animatedGIF类

关于ios - UIWebView 中的动图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28370348/

相关文章:

iphone - device Orientation 到 statusBar Orientation 改变

swift - 断言失败 UITableView : delete object which a relationship to another object

ios - Swift 3.0 中的 POST 请求

swift - 将 CoreMIDI 输入与 AVAudioUnit 结合使用

ios - 如何在tableview cell swift 3.0中设置选中的复选标记

ios - 如何静音入站电子邮件通知、消息等?

ios - Unity3d项目移植到IOS后可以编辑和添加代码吗?

ios - Xcode 9 - "Fixed Width Constraints May Cause Clipping"和其他本地化警告

ios - iOS 9 中 UILabel 中的多行文本

c++ - opencv 保存从网络摄像头捕获的图像