Animated GIF does not work on iPhone

假装没事ソ 提交于 2019-12-03 07:18:12
Nathan de Vries

UIImageView provides the necessary APIs to produce your own animations like this:

UIImage *frame1 = [UIImage imageNamed:@"frame1.png"];
UIImage *frame2 = [UIImage imageNamed:@"frame2.png"];
UIImage *frame3 = [UIImage imageNamed:@"frame3.png"];
UIImage *frame4 = [UIImage imageNamed:@"frame4.png"];


UIImageView.animationImages = [[NSArray alloc] initWithObjects:frame1, frame2, frame3, frame4, nil];
UIImageView.animationDuration = 1.0 //defaults is number of animation images * 1/30th of a second
UIImageView.animationRepeatCount = 5; //default is 0, which repeats indefinitely
[UIImageView startAnimating];

//[uiImageView stopAnimating];

In iPhone OS 3.0, cell.image is no longer supported. Instead, cell's have an imageView property, which gives you some more flexibility. You can split the animated gif up into separate images, and then do this:

anImageView *UIImageView = [[UIImageView alloc] init];
anImageView.animationImages = imagesArray; //this is an array of UIImages you have to create

Only UIWebView supports to display an animated GIF file.

Can you please see the following code I hope it will be helpful to you...

1. Remove the animation code in cellforatindexpath

2. animate it when cell is displaying

3. stop animation while hiding the cells

4. Will Improve the performance of the App

5. Save more memory

    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *myImageArray = [NSArray arrayWithObjects:
                             [UIImage imageNamed:@"image1.png"],
                             [UIImage imageNamed:@"image2.png"],
                             [UIImage imageNamed:@"image3.png"],
                             [UIImage imageNamed:@"image4.png"],
                             [UIImage imageNamed:@"image5.png"],nil];

    [cell.imageView setAnimationImages:myImageArray];
    cell.imageView.animationDuration = 4.0;
    cell.imageView.animationRepeatCount = 1;
    [cell.imageView startAnimating];
    }

     -(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    [cell.imageView stopAnimating];
    [cell.layer removeAllAnimations];
    }  

Your only choices are to code own mechanism of rendering the gif in a view or wait for apple to fix it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!