首页 > 移动平台 > 详细

4.ios之图片动画加载

时间:2014-12-25 22:11:54      阅读:290      评论:0      收藏:0      [点我收藏+]

1.UIImageView animationImages属性

1加入图片后会占用内存不自动释放

2> animationImages 赋值 nil 时才会自动释放之前加载图片的内存

- (void)runAnimationWithCount:(int)count name:(NSString *)name
{
    if (self.tom.isAnimating) return;
    
    // 1.加载所有的动画图片
    NSMutableArray *images = [NSMutableArray array];
    
    for (int i = 0; i<count; i++) {
        // 计算文件名
        NSString *filename = [NSString stringWithFormat:@"%@_%02d.jpg", name, i];
        // 加载图片
        
        // imageNamed: 有缓存(传入文件名)
//        UIImage *image = [UIImage imageNamed:filename];
        
        // imageWithContentsOfFile: 没有缓存(传入文件的全路径)
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:filename ofType:nil];
        UIImage *image = [UIImage imageWithContentsOfFile:path];
        
        // 添加图片到数组中
        [images addObject:image];
    }
    self.tom.animationImages = images;
    
    // 2.设置播放次数(1次)
    self.tom.animationRepeatCount = 1;
    
    // 3.设置播放时间
    self.tom.animationDuration = images.count * 0.05;
    
    [self.tom startAnimating];
    
    // 4.动画放完1秒后清除内存
    CGFloat delay = self.tom.animationDuration + 1.0;
    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];
//    [self performSelector:@selector(clearCache) withObject:nil afterDelay:delay];
}




4.ios之图片动画加载

原文:http://blog.csdn.net/neng18/article/details/42152873

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!