我正在使用cell.image = 一个动态gif文件
(cell是UITableViewCell
)。然而,它没有动画效果。有没有什么方法可以修复它?
我正在使用cell.image = 一个动态gif文件
(cell是UITableViewCell
)。然而,它没有动画效果。有没有什么方法可以修复它?
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];
在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
-(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];
}
只有UIWebView支持显示动画GIF文件。
你唯一的选择是编写自己的机制来在视图中呈现gif,或者等待苹果修复它。
UIImageView *animatedImageView; animatedImageView.animationImages = ...; animatedImageView.animationDuration = ...; ...;
- Neeku