Talking Tom Source Code

来源:互联网 发布:js打开无导航栏新窗口 编辑:程序博客网 时间:2024/05/21 23:01

Talking Tom


- (void)runAnimationWithCount:(int)count name:(NSString *)name

{

    if (self.tom.isAnimating)return;

    

    // 1.加载所有的动画图片

    NSMutableArray *images = [NSMutableArrayarray];

    

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

       // 计算文件名

       NSString *filename = [NSStringstringWithFormat:@"%@_%02d.jpg", name, i];

       // 加载图片

        

        // imageNamed: 有缓存(传入文件名)

//        UIImage *image = [UIImage imageNamed:filename];

        

        // imageWithContentsOfFile: 没有缓存(传入文件的全路径)

       NSBundle *bundle = [NSBundlemainBundle];

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

       UIImage *image = [UIImageimageWithContentsOfFile:path];

        

        // 添加图片到数组中

        [imagesaddObject:image];

    }

   self.tom.animationImages = images;

    

    // 2.设置播放次数(1)

    self.tom.animationRepeatCount =1;

    

    // 3.设置播放时间

    self.tom.animationDuration = images.count * 0.05;

    

    [self.tomstartAnimating];

    

    // 4.动画放完1秒后清除内存

    CGFloat delay =self.tom.animationDuration +1.0;

    [self.tomperformSelector:@selector(setAnimationImages:)withObject:nilafterDelay:delay];

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

}



0 0
原创粉丝点击