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 }
  • 相关阅读:
    面向对象的本质是算法的上下文封装,是同一类属的行为接口的一致性
    结构化方法和面向对象方法的比较
    需求文档和软件都是服务的集合
    注意 Laravel 清除缓存 php artisan cache:clear 的一个坑
    面向对象复习笔记(一)
    详解如何在Laravel中增加自定义全局函数
    Laravel 引入自定义类库或第三方类库
    PHP怎么调用其他类的方法
    Laravel如何引用第三方(自定义)库
    laravel框架手机发送验证码
  • 原文地址:https://www.cnblogs.com/anRanTimes/p/5094037.html
Copyright © 2011-2022 走看看