在UIImageview中使用动画时收到了内存警告,例如[smyImageView startAnimating]; [英] Received memory warning, while using animations in UIImageview like [smyImageView startAnimating];

查看:147
本文介绍了在UIImageview中使用动画时收到了内存警告,例如[smyImageView startAnimating];的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

//NsMutableArray 
//Received memory warning, while using  animations in UIImageview like; 
self.imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT];

// Build array of images, cycling through image names
if (![self.imageArray count]>0) {
    for (int i = 0; i < IMAGE_COUNT; i++){
        if (i<10) {
         [self.imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image000%d.jpg", i]]];

        }else {

         [self.imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"image00%d.jpg", i]]];

        }
    }
}   

/////Received memory warning, while using  animations in UIImageview
self.animatedImages.animationImages = [NSArray arrayWithArray:self.imageArray];
[self.imageArray release];
self.imageArray=nil;

// One cycle through all the images takes 1.5 seconds
self.animatedImages.animationDuration = 0.8;
// Repeat forever
self.animatedImages.animationRepeatCount = -1;
[self.animatedImages startAnimating];

推荐答案

替换

[UIImage imageNamed:[NSString stringWithFormat:@"image000%d.jpg", i]]

使用

[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"image000%d.jpg", i] ofType:nil]]];

因为API imageNamed:在内存中缓存数据.

because the API imageNamed: cache data in memory.

这篇关于在UIImageview中使用动画时收到了内存警告,例如[smyImageView startAnimating];的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆