本文介绍了用循环顺序显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一张5张图片的NSArray。我想在循环中一个接一个地显示它们。
我的代码:

I got an NSArray with 5 pictures. I want to display them one after the other in a loop.My code :

 NSArray *tabImage = [[NSArray alloc] init];

tabImage = [[NSArray arrayWithObjects:
               [UIImage imageNamed:@"picto_1.png"],
               [UIImage imageNamed:@"picto_2.png"],
               [UIImage imageNamed:@"picto_3.png"],
               [UIImage imageNamed:@"picto_4.png"],
               [UIImage imageNamed:@"picto_5.png"],
               nil] retain];

int var = 0;
var = indexPath.row;

for (int var = 0; var < 20; var++) {
    pictoImage.image = [tabImage objectAtIndex:(var % 5)];
}

我得到了相同的图片。

感谢您的帮助。

推荐答案

我猜猜 pictoImage 是一个 UIImageView 。在这种情况下,请查看,特别是 animationImages 属性。

I’m guessing pictoImage is an UIImageView. In that case look at the class reference, specifically the animationImages properties.

 pictoImage.animationImages = [NSArray arrayWithObjects:
                                   [UIImage imageNamed:@"picto_1.png"],
                                   [UIImage imageNamed:@"picto_2.png"],
                                   [UIImage imageNamed:@"picto_3.png"],
                                   [UIImage imageNamed:@"picto_4.png"],
                                   [UIImage imageNamed:@"picto_5.png"],
                                   nil];

 // How many seconds it should take to go through all images one time.
 pictoImage.animationDuration = 5.0;

 // How many times to repeat the animation (0 for indefinitely).
 pictoImage.animationRepeatCount = 4;

 [pictoImage startAnimating];

这篇关于用循环顺序显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:42