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:
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?
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?
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With