Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show a GIF on iOS in a certain frame, not show it until fully loaded, and allow zoom?

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

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.

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

  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)?

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

  3. 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?

like image 426
Doug Smith Avatar asked Dec 11 '13 21:12

Doug Smith


1 Answers

1.

The first solution that comes to mind is to set the background of the webview to clear color and place it in the right location after it finishes loaded. Usually I use

[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"]

but that won't work if you are directing your webview to a gif url.

2.

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    webView.alpha = 1;
}

That way the UIWebView will be shown to the user only after the gif is full loaded.

3.

[webView setScalesPageToFit:YES];
like image 87
Segev Avatar answered Oct 06 '22 00:10

Segev