zoukankan      html  css  js  c++  java
  • 帧动画的完整实现: 代码直接演示

    帧动画的完整实现:  

     直接上代码演示更加清晰

     1 帧动画完整代码实现:
     2 #import "ViewController.h"
     3 @interface ViewController ()
     4 
     5 @property (weak, nonatomic) IBOutlet UIImageView *imageViewIcon;
     6 
     7 @end
     8 
     9 @implementation ViewController
    10 
    11 //把相同的代码封装一下
    12 -(void)beginAnimationWithImageCount:(int) a imageName:(NSString *)imageName
    13 {
    14 //调用isAnimating方法,判断动画是否在执行中,如果在必须执行完成之后再执行其他的动画,得有判断if
    15 if (self.imageViewIcon.isAnimating)return;
    16 
    17 //1.把需要执行的动画图片设置到UIImageView(图片框)
    18 NSMutableArray *array=[NSMutableArray array];
    19 
    20 for (int i=0; i<a; i++) {
    21 NSString *image=[NSString stringWithFormat:@"%@%03d",imageName,i+1];
    22 
    23 // UIImage *img=[UIImage imageNamed:image]; 通过这种方式来加载的数据是有缓存的,
    24 //如果用路径的方式创建,就不会有缓存
    25 NSString *img_path=[[NSBundle mainBundle]pathForResource:image ofType:@"png"];
    26 UIImage *img=[UIImage imageWithContentsOfFile:img_path]; //
    27 //注意:这里如果没有吧素材加载到Supporting Files中时,会显示为空,所以用路径方式的时候,要把素材都加到Supporting Files中
    28 
    29 [array addObject:img];
    30 }
    31 
    32 //把要执行的动画的图片数组 设置给图片框的animationImages属性
    33 self.imageViewIcon.animationImages=array;
    34 
    35 //2.设置动画的持续时间 让每一张图片都执行0.1秒
    36 self.imageViewIcon.animationDuration=0.1*self.imageViewIcon.animationImages.count;
    37 
    38 //3.设置动画的重复次数
    39 self.imageViewIcon.animationRepeatCount=1;
    40 
    41 //4.启动动画
    42 [self.imageViewIcon startAnimating];
    43 
    44 //等待动画执行完毕后,再清理内存 performSelector :set方法 withObject对象 afterDelay时间
    45 [self.imageViewIcon performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imageViewIcon.animationDuration];
    46 
    47 }
  • 相关阅读:
    分布式缓存
    分布式事务
    数据库系列-分库分表
    消息队列系列-简介
    JAVA系列-引用
    生产环境CPU占用过高分析
    技术书单(部分)
    GitHub的强大搜索功能简介
    VS2019 community版本下载Extension太慢解决方案
    Python2同时输出中文和变量时中文乱码
  • 原文地址:https://www.cnblogs.com/anRanTimes/p/5094037.html
Copyright © 2011-2022 走看看