iOS为imageView添加图片实现动画代码如下:
//创建imageView | |
| self.imageView= [[UIImageViewalloc]initWithFrame:CGRectMake(0,40,320, 260)]; |
| |
| //把图片添加到动态数组 |
| NSMutableArray * animateArray = [[NSMutableArrayalloc]initWithCapacity:20]; |
| [animateArray addObject:[UIImage imageNamed:@"t1.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t2.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t3.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t4.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t5.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t6.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t7.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t8.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t9.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t10.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t11.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t12.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t13.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t14.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t15.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t16.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t17.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t18.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t19.png"]]; |
| [animateArray addObject:[UIImage imageNamed:@"t20.png"]]; |
| |
| //为图片设置动态 |
| self.imageView.animationImages= |
| //为动画设置持续时间 |
| self.imageView.animationDuration=3.0; |
| //为默认的无限循环 |
| self.imageView.animationRepeatCount=0; |
| |
| //开始播放动画 |
| [self.imageView startAnimating]; |
| [self.view addSubview:self.imageView]; |