如何在某个帧中在iOS上显示GIF,在完全加载之前不显示它,并允许缩放? [英] How to show a GIF on iOS in a certain frame, not show it until fully loaded, and allow zoom?

查看:284
本文介绍了如何在某个帧中在iOS上显示GIF,在完全加载之前不显示它,并允许缩放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户选择GIF时,我想在显示GIF的所有内容上显示叠加层。

When a user selects a GIF, I want to present an overlay on top of everything showing the GIF.

我知道在iOS上有几种方法可以做到这一点。有很好的 UIImage + animatedGIF 可以很好地运行,但是对于更长的GIF来说,它们非常慢并且没有以与UIWebView相同的速度播放(以准确的播放速度播放)。

I know there's a few ways on iOS to do this. There's the great UIImage+animatedGIF which works decently well, but for longer GIFs they're very slow and don't play back at the same speed as a UIWebView would (which plays at the accurate playback speed).

它很糟糕,因为如果该类别没有播放它们慢慢地它会做我需要的一切。

It sucks, because if that category didn't play them back slowly it would do everything I need.

但事实并非如此,所以我尝试使用UIWebView,但是我对三件事感到困惑:

But it doesn't, so I tried with UIWebView, however I'm confused about three things:


  1. 如何获得UIWebView在呈现时的大小(其框架)?我是否必须首先下载GIF作为UIImage,然后检查其 size 属性?有没有更好的方法(可能需要一段时间)?

  1. How do I get size that the UIWebView should be when presented (its frame)? Would I have to download the GIF first as a UIImage then check its size property? Is there a better way (might take awhile)?

如何在完全加载之前阻止它播放?

How do I stop it from playing until it's fully loaded?

使用上面的类别,因为它只是一个UIImage,当我在滚动视图中将它作为UIImageView嵌入时,它很容易放大和缩小。 UIWebview可以实现吗?

With the above category, as it's just a UIImage, when I embed it as a UIImageView in a scrollview it's very easy to zoom in and out of. Is this possible with a UIWebview?


推荐答案

你可以使用它拥有的SDWebImage动画GIF支持

You can use SDWebImage it has Animated GIF support

https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImage%2BGIF.m

        _block BOOL flag = NO;
        NSURL *imageURL = [NSURL URLWithString:@"ImageUrl" relativeToURL:@"mainURL"] ;
        SDWebImageManager *manager = [SDWebImageManager sharedManager];
        [manager downloadWithURL:imageURL
                         options:0
                        progress:^(NSUInteger receivedSize, long long expectedSize)
         {
         }
                       completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
         {
             if (image){
                 flag = YES;
                 downloadProgress++;
             }
         }];

这篇关于如何在某个帧中在iOS上显示GIF,在完全加载之前不显示它,并允许缩放?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆