汤姆猫(。。。。)

1:如何使用UIImageView播放动画

2:从bundle中加载图片的两种方式

3怎么样延迟执行某个方法

项目的源码以及素材

链接: http://pan.baidu.com/s/1hq4fWrE 密码: xqkw

主要的修改有:使用switch case来进行点击事件的区分。

核心代码是:

-(void)actionWithFilename:(NSString *)name andImgCount:(NSInteger)count{

    NSMutableArray *imgArr = [NSMutableArray array];

    for (int i = 0; i<count; i++) {

         NSString *imgName = [NSString stringWithFormat:@"%@%02d.jpg",name,i];

        NSString *path = [[NSBundle mainBundle]pathForResource:imgName ofType:nil];

        UIImage *image = [UIImage imageWithContentsOfFile:path];//系统不缓存图片

//        UIImage *image = [UIImage imageNamed:imgName];//如果使用这种方法来加载bundle中的图片的时候,系统会自动缓存这些图片

        

        [imgArr addObject:image];

    }

    

    self.backIV.animationImages = imgArr;//注意这里的数组里存放的是image而不是字符串

    [self.backIV setAnimationImages:imgArr];

    self.backIV.animationDuration = count * .1;

    self.backIV.animationRepeatCount = 1;

    [self.backIV startAnimating];

    CGFloat time = self.backIV.animationRepeatCount * self.backIV.animationDuration;

//    延迟执行某个方法

//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

//        self.backIV.animationImages = nil;//清除动画需要的图片

//    });

    

    //就是将nil赋值给了AnimationImages 即[self.backIV setAnimationImages:nil];

    [self.backIV performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:time];

}

原文地址:https://www.cnblogs.com/mudy/p/4831587.html