- (void)viewDidLoad { //定义数组,存放所有图片对象 NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"xuanyi.jpg"],[UIImage imageNamed:@"xigua.jpg"],[UIImage imageNamed:@"juhua.jpg"],[UIImage imageNamed:@"heihua.jpg"],[UIImage imageNamed:@"cell.jpg"], nil]; //定义结构体,方块大小 CGRect frame=CGRectMake(0, 0, 320, 460); //初始化图像视图对象,大小是frame UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame]; //imageView的动画图片是数组images imageView.animationImages = images; //按照原始比例缩放图片,保持纵横比 imageView.contentMode = UIViewContentModeScaleAspectFit; //切换动作的时间3秒,来控制图像显示的速度有多快, imageView.animationDuration = 3; //动画的重复次数,想让它无限循环就赋成0 imageView.animationRepeatCount = 0; //开始动画 [imageView startAnimating]; //添加控件 [self.view addSubview:imageView]; //释放内存 [imageView release]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. }