我正在尝试在"表格视图单元格"中设置UIImageview
动画,但图像从不显示。
这是我试图使用的代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
cell.textLabel.font = [UIFont systemFontOfSize:16.0];
}
if (cell)
{
cell.textLabel.text = [titleArray objectAtIndex:indexPath.row];
cell.textLabel.textColor = [UIColor darkGrayColor];
UIImage *musicOne = [UIImage imageNamed:@"music1.png"];
UIImage *musicTwo = [UIImage imageNamed:@"music2.png"];
UIImage *musicThree = [UIImage imageNamed:@"music3.png"];
NSArray *imagesArray = [NSArray arrayWithObjects:musicOne, musicTwo, musicThree, nil];
if (indexPath.row == 0)
{
cell.imageView.animationImages = imagesArray;
cell.imageView.animationDuration = 1.0f;
cell.imageView.animationRepeatCount = 0;
[cell.imageView startAnimating];
}
}
return cell;
}
如果我没有尝试使用多张图片制作动画,并且只是在图片视图中使用一张图片,则图片会显示在单元格中。
cell.imageView.image = [imagesArray objectAtIndex:0];
答案 0 :(得分:3)
有必要将image
的{{1}}属性与cell.imageView
一起设置,否则animationImages
将不显示任何内容。
为了提高应用程序的性能并节省内存,请执行以下操作:
UITableViewCell
答案 1 :(得分:0)
尝试给imageView一个标签(例如1),然后得到如下图像视图:
UIImage *musicOne = [UIImage imageNamed:@"music1.png"];
UIImage *musicTwo = [UIImage imageNamed:@"music2.png"];
UIImage *musicThree = [UIImage imageNamed:@"music3.png"];
NSArray *imagesArray = [NSArray arrayWithObjects:musicOne, musicTwo, musicThree, nil];
if (indexPath.row == 0)
{
UIImageView *imageView = (UIImageView *)[cell viewWithTag:1];
imageView.animationImages = imagesArray;
imageView.animationDuration = 1.0f;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
}
答案 2 :(得分:0)
这个完全相同的代码对我有用。我知道UIScrollView
动画会在视图滚动时停止播放,因此您应该使用CADisplayLink
在NSRunLoopCommonModes
而不是NSDefaultRunLoopMode
上运行动画,但我已经测试过你的代码,它工作。