如何让一个gif永远不会停止在UIWebView?

时间:2014-11-12 17:19:01

标签: ios ios7 uiwebview ios8

我在UIWebView中有一个Gif,但是当动画结束时,它会停止。 我怎么做永不停止?

这是我的代码:

self.video是我的UiWebView 我的gif是videoGif.gif

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.video.delegate=self;
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"videoGif" ofType:@"gif"];

    NSData *gif = [NSData dataWithContentsOfFile:filePath];
    [self.video loadData:gif MIMEType:@"image/gif" textEncodingName:nil baseURL:nil];

    self.video.userInteractionEnabled = NO;
    self.video.scalesPageToFit=YES;
    self.video.contentMode = UIViewContentModeScaleAspectFit;
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    self.video.scalesPageToFit=YES;
    self.video.contentMode = UIViewContentModeScaleAspectFit;
}

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以使用UIView动画。在这里,我使用UIButton进行动画制作。它可能是替代方式。这是我的代码:

NSMutableArray *imageArray=[NSMutableArray new];
for(int i=1;i<=16;i++){
    [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"win_%d.png",i]]];
}
[animatedButton setImage:[UIImage imageNamed:@"win_1.png"] forState:UIControlStateNormal];
[animatedButton.imageView setAnimationImages:[imageArray copy]];
animatedButton.imageView.animationDuration = .50;
[animatedButton.imageView startAnimating];