zoukankan      html  css  js  c++  java
  • IOS 动画播放案例

    #import "ViewController.h"
    
    @interface ViewController ()
    @property (weak,nonatomic) IBOutlet UIImageView *imageView;
    - (IBAction)head;
    @end
    @implementation ViewController
    
    - (IBAction)head {
       // 图片张数, 图片名称
        [self SetDataInfo:81 PicName:@"knockout"];
    }
    
    -(void) SetDataInfo:(int)count PicName:(NSString*)PicName{
        //当imageView图片框正在执行动画,则return
        if  (self.imageView.isAnimating)
        {
            return;
        }
        //声明数组
        NSMutableArray * arrayM = [NSMutableArray array];
        //循环取得图片名称,并添加到数组中
        for(int i  = 0; i < count; i++)
        {
            //拼接图片名称
            NSString *imgName =[NSString stringWithFormat:@"%@_%02d.jpg",PicName,i];
            //获取图片完整路径,不使用缓存
            //另一种方试调用imageNamed:这种方式是图片保存到内存当中,占用内存过大
            NSString *path =[[NSBundle mainBundle] pathForResource:imgName ofType:nil];
            //根据图片路径取到图片
            UIImage* imgCat = [UIImage imageWithContentsOfFile:path];
            //添加到数组
            [arrayM addObject:imgCat];
        }
         //1.设置UIImageView (图片框) 的animationImages 属性,这个属性中包含所有要执行的动画图片
        self.imageView.animationImages =arrayM;
         //2.设置动画持续时间
        self.imageView.animationDuration =self.imageView.animationImages.count * 0.1;
         //3.设置动画是否重复播放
        self.imageView.animationRepeatCount = 1;
         //4.开启动画
        [self.imageView startAnimating];
        //设置图片框在调用setAnimationImages:nil 方法的时候延迟执行
        [self.imageView performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.imageView.animationImages.count *0.1];
  • 相关阅读:
    小白初学iOS中OTA部署(适应iOS7.1)
    CocoaPods管理本地库简单步骤
    CocoaPods问题记录
    UIPanGestureRecognizer下方法
    2013年度总结(反思篇)
    iOS7中cell的分割线右移的解决方法
    接触CocoaPods遇到的问题
    iOS摄像头问题
    iPhone4激活出错,菜鸟试验!!!!!
    详解UIPickerView
  • 原文地址:https://www.cnblogs.com/zzgt/p/4739500.html
Copyright © 2011-2022 走看看