代码之家  ›  专栏  ›  技术社区  ›  Jigar Joshi

如何在iphone uiimageview上显示gif图像

  •  2
  • Jigar Joshi  · 技术社区  · 15 年前

    我已经找到了一些方法,但它们实际上是读取帧并应用转换,这会降低动画的质量。 有没有办法在iphone应用程序上显示gif呢? 提前谢谢..

    2 回复  |  直到 8 年前
        1
  •  12
  •   runmad    15 年前

    动画gif不会设置动画,但如果有gif,请将每个动画另存为一个单独的gif,然后使用刚才保存的所有gif设置动画图像数组:

    UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    animatedImageView.animationImages = [NSArray arrayWithObjects:    
                                   [UIImage imageNamed:@"image1.gif"],
                                   [UIImage imageNamed:@"image2.gif"],
                                   [UIImage imageNamed:@"image3.gif"],
                                   [UIImage imageNamed:@"image4.gif"], nil];
    animatedImageView.animationDuration = 1.0f;
    animatedImageView.animationRepeatCount = 0;
    [animatedImageView startAnimating];
    [self.view addSubview: animatedImageView];
    
        2
  •  0
  •   Jesse Tayler    8 年前

    使用Web视图。

        if let path = Bundle.main.path(forResource: "animated", ofType: "gif") {
            let url = URL(fileURLWithPath: path)
            let request = URLRequest.init(url: url)
            webview.loadRequest(request)
        }
    

    这将渲染图像并按预期设置动画。