我是iphone的初学者,我在阵列中拥有所有图像但是当我在循环中执行数组时如何逐个显示..
NSArray *images = [[NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
[UIImage imageNamed:@"4.png"],
nil] retain];
int i=0;
int width = 0;
int height = 0;
for ( NSString *imageName in images )
{
//NSTimer *timer=[[NSTimer alloc]init];
UIImage *image = [images objectAtIndex:i];
//UIImage *image = [UIImage imageNamed:imageName];
animalphoto = [[UIImageView alloc] initWithImage:image];
animalphoto.contentMode = UIViewContentModeScaleAspectFit;
animalphoto.clipsToBounds = YES;
animalphoto.animationDuration=5.0;
animalphoto.animationRepeatCount=0;
animalphoto.frame = CGRectMake( animalphoto.frame.size.width * i++, 0, animalphoto.frame.size.width, animalphoto.frame.size.height);
width = animalphoto.frame.size.width;
height = animalphoto.frame.size.height;
NSLog(@"print:%@",image);
[animalphoto release];
}
}
提供适用于我们代码的任何建议和示例代码..
答案 0 :(得分:1)
而不是将一个图像放入imgview.animationImages =图像而不是for循环
如需进一步参考,请访问this网站。
答案 1 :(得分:0)
您需要使用UIImageView's
对象animationImages
来设置UIImage
数组
设置animationRepeatCount
设置animationDuration
然后调用[imageView startAnimating];
开始动画