释放双眼,带上耳机,听听看~!
//创建UIImageView对象:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.frame];
imageView.backgroundColor = [UIColor orangeColor];
//为imageView设置图片:
// imageView.image = [UIImage imageNamed:@"2.jpg"];
//植物大战僵尸动画:(素材要自己找)
//(1)设置整体背景:
imageView.image = [UIImage imageNamed:@"BackGround"];//png的图知道名字即可,最好使用png格式的图片
//(2)循环创建动画素材(UIImage对象)
NSMutableArray *flowerArray = [NSMutableArray array];
for (NSInteger i = 1; i <= 18; i++) {
//拼接每个图片的名字:
NSString *name = [NSString stringWithFormat:@"flower%ld.tiff", i];
UIImage *image = [UIImage imageNamed:name];
[flowerArray addObject:image];
}
//(3)创建单独的UIImageView控件
UIImageView *flowerImageView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 80, 73, 74)];
[imageView addSubview:flowerImageView];
//(4)将数组赋值给imageView:
flowerImageView.animationImages = flowerArray;
//(5)设置时间间隔(每两张图片之间播放的时间差)
flowerImageView.animationDuration = 1.8f;
//(6)设置一下重复次数:
// flowerImageView.animationRepeatCount = 5;
//(7)开始动画:
[flowerImageView startAnimating];
//花儿动起来:
[UIView animateWithDuration:8 animations:^{
flowerImageView.frame = CGRectMake(200, 400, 73, 74);
}];
//添加到view上
[view addSubview:imageView];