//获取图片路径:相对路径
//第一个参数:文件的名字
//第二个参数:文件的类型
NSString *path = [[NSBundle mainBundle] pathForResource:@"map" ofType:@"png"];
UIImage *imagePath = [UIImage imageWithContentsOfFile:path];
UIImageView *imageViewPath = [[UIImageView alloc] initWithFrame:CGRectMake(20, 130, 200, 50)];
imageViewPath.image = imagePath;
/****动画效果相关属性****/
//创建图片数组
//开辟内存空间
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:0];
for (int i = 1; i <= 12; i ++) {
[array addObject:[UIImage imageNamed:[NSString stringWithFormat:@"player%d.png",i]]];
}
//设置动画图片,需要接收一个数组,数组里面的类型必须是UIImage类型
imageView.animationImages = array;
//动画时间:数组里面所有的图片转一圈所用时间
imageView.animationDuration = 1;
//循环次数:大于0的数:写几就循环几次,结束 0:无限循环
imageView.animationRepeatCount = 0;
//开始动画
[imageView startAnimating];
//按钮点击开始或结束
static BOOL isAnimation = YES;//static静态变量用过立即释放
if (isAnimation)
{//等价于isAnimation为真(isAnimation==YES)
[imageView stopAnimating];
isAnimation = NO;
//这时的isAnimation=YES被释放为空,接着
//赋值为NO再次点击按钮时isAnimation=NO;
}
else
{
[imageView startAnimating];
isAnimation = YES;
}
//定时器
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(birdFly:) userInfo:nil repeats:YES];
网友评论