Received memory warning, while using animations in UIImageview like [smyImageView startAnimating];

最后都变了- 提交于 2019-12-25 01:18:05

问题


//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];

回答1:


Replace

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

with

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

because the API imageNamed: cache data in memory.



来源:https://stackoverflow.com/questions/8939722/received-memory-warning-while-using-animations-in-uiimageview-like-smyimagevie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!