ios - 如何让 gif 在 UIWebView 中永不停止?

标签 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;
}

谢谢!!

最佳答案

您可以使用 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];

关于ios - 如何让 gif 在 UIWebView 中永不停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26892744/

相关文章:

ios - 使用 NSUserdefaults Swift 首次加载整数时出错

ios - 为什么不能将 UITableViewCell 实例用作计算属性?

iphone - 如何将 NSURL fileURLWithPath 与片段一起使用?

ios - 如何获得 UIWebView 的适当滚动内容大小?

ios - 如何修复 Xcode "DTAssetProviderService could not start.."错误?

ios - 与 watch 套件扩展和 iPhone 应用程序通信

iOS 版本 : if I have an app with specific "minor" device required, 如何在同一应用程序中使用更新设备的优势?

ios7 - 我可以为iOS7专用的应用程序转储非Retina图像吗?

ios - UIKeyboard 在 iOS7 中不会自动半透明

iphone - 如何将外部样式表添加到 Xcode 中的 UIWebView?