【问题标题】:How to Display GIF Image on iPhone UIIMageView如何在 iPhone UIIMageView 上显示 GIF 图像
【发布时间】:2016-10-24 05:44:41
【问题描述】:

我找到了一些方法,但它们实际上是在读取帧并应用降低动画质量的过渡。 有没有办法在 iPHone 应用程序上显示 GIF 原样..? 在此先感谢..

【问题讨论】:

  • 必须使用 GIF 吗?你能用一个PNG序列来代替吗?
  • 您想要显示动画 GIF?

标签: iphone uiimageview


【解决方案1】:

动画 GIF 不会动画,但如果您有 GIF,请将每个动画另存为单独的 GIF,然后使用您刚刚保存的所有 GIF 设置 animationImages 数组:

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】:

    使用网络视图。

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

    这将呈现您的图像并按预期对其进行动画处理。

    【讨论】:

      猜你喜欢
      • 2020-05-29
      • 2012-08-28
      • 2013-05-13
      • 2011-05-22
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 2011-02-08
      • 1970-01-01
      相关资源
      最近更新 更多