0

我是 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];
    }


}

给出适用于我们代码的任何建议和示例代码。

4

2 回答 2

1

而不是放置一个图像,只需将整个图像数组放入 imgview.animationImages = images 而不是 for 循环

如需进一步参考,请访问网站。

于 2012-07-05T11:15:18.510 回答
0

您需要使用UIImageView'sobjectanimationImages设置UIImage数组
set animationRepeatCount
setanimationDuration
然后调用[imageView startAnimating];以启动动画

于 2012-07-05T11:15:17.837 回答