_Vi = [[UIView alloc]initWithFrame:CGRectMake(100, 200, 200, 200)]; //定义数组,存放所有图片对象 NSArray *images=[NSArray arrayWithObjects:[UIImage imageNamed:@"image003.jpg"],[UIImage imageNamed:@"image004.jpg"], nil]; // //定义结构体,方块大小 // CGRect frame=CGRectMake(100, 100, 200, 200); //初始化图像视图对象,大小是frame _imageView = [[UIImageView alloc] initWithFrame:_Vi.bounds]; //imageView的动画图片是数组images _imageView.animationImages = images; //按照原始比例缩放图片,保持纵横比 _imageView.contentMode = UIViewContentModeScaleAspectFit; //切换动作的时间0.5秒,来控制图像显示的速度有多快, _imageView.animationDuration = 0.5; //动画的重复次数,想让它无限循环就赋成0 _imageView.animationRepeatCount = 0; //开始动画 [_imageView startAnimating]; //添加控件 [_Vi addSubview:_imageView]; [self.view addSubview:_Vi];