问题
I am using cell.image = an animated gif file
(cell is UITableViewCell
). However, it does not animate. Is there any way I can fix it?
回答1:
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];
回答2:
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
回答3:
Only UIWebView supports to display an animated GIF file.
回答4:
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];
}
回答5:
Your only choices are to code own mechanism of rendering the gif in a view or wait for apple to fix it.
来源:https://stackoverflow.com/questions/973177/animated-gif-does-not-work-on-iphone