【问题标题】:Received memory warning, while using animations in UIImageview like [smyImageView startAnimating];收到内存警告,同时在 UIImageview 中使用动画,如 [smyImageView startAnimating];
【发布时间】:2012-02-14 22:03:10
【问题描述】:
//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];

【问题讨论】:

    标签: iphone memory-management xcode4 iphone-sdk-4.1


    【解决方案1】:

    替换

    [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: 在内存中缓存数据。

    【讨论】:

    • 谢谢拉克什。很快会在设备上查看。
    猜你喜欢
    • 2013-03-05
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多