序列帧动画

1 png图片建议放在Images.xcassets文件中

2 jpg图片放在Images.xcassets文件中不支持,拖到Supporting Files文件中

3 加载图片

//1.加载多有动画图片

    if(self.imageView.isAnimation) retrun;

    NSMutableArray *images=[NSMutableArray array];

    fot(int i=0;i<80;i++){

        //计算文件名

         NSString *filename=[NSString stringWithFormat:@"drink_%02d.jpg",i];           //  drink_%02d.jpg     意为: %2 为占位     中间0   不够的用0补齐      drink_07.jpg

        //加载图片

        UIImage *image=[UIImage imageNamed:filename];

        //添加图片到数组

         [images addObjest:image];

}

         self. imageView.animationImages=images;

//2.设置播放次数

 self.imageView.animationRepeatCount=1;

//3.设置播放时间

self.imageView.animationDuration=images.count*0.05           images.count*0.05目的:保证匀速  

 [self.imageView startAnimating];

  CGFloat delay=self.imageView.animationDuration+1.0;

  [self performSelector:@selector(clearCache) withObject:nil afterDelay:delay];



在执行某一动画时不允许做其他添加一行代码  if(self.imageView.isAnimation) retrun;


加载imageView的两种方式

    imageNamed  有缓存,传文件名

   UIImage *image=[UIImage imageNamed:filename];      适合加载小型图片,会有缓存,加载大型图片不建议

   imageWithContentsOffFile 没有缓存,传文件的全路径

   NSBundle *bundle=[NSBundle mainBundle];

   NSString *path=[bundle pathForResource:filename ofType:nil];

   UIImage *image=[UIImage imageWithContentsOffFile:path];


程序动画执行后会释放内存

  CGFloat delay=self.imageView.animationDuration+1.0;

  [self performSelector:@selector(clearCache) withObject:nil afterDelay:delay];

-(void)clearCache{

self.imageView.animationImages=nil;

}

上述代码又可简化为 [self performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];     //给setAnimationImages:传一个参数为空


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值