动态GIF在iPhone上无法使用

7

我正在使用cell.image = 一个动态gif文件(cell是UITableViewCell)。然而,它没有动画效果。有没有什么方法可以修复它?

5个回答

16

UIImageView提供必要的API来制作类似于此的动画:

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];

这是一个有帮助的答案,但更精确的代码应该是: UIImageView *animatedImageView; animatedImageView.animationImages = ...; animatedImageView.animationDuration = ...; ...; - Neeku

2

在iPhone OS 3.0中,不再支持cell.image。相反,cell具有imageView属性,这使您具有更多的灵活性。您可以将动画gif拆分为单独的图像,然后执行以下操作:

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

1
请看以下代码,希望对您有所帮助...
1. 在cellforatindexpath中删除动画代码 2. 在单元格显示时进行动画处理 3. 隐藏单元格时停止动画 4. 将提高应用程序的性能 5. 节省更多内存
    -(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];
    }  

1

只有UIWebView支持显示动画GIF文件。


-2

你唯一的选择是编写自己的机制来在视图中呈现gif,或者等待苹果修复它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接