开发者

UIImageView animation causing crash

I have a UIAnimation view that plays an array of PNG images as an animation. There are about 200 frames and total size is about 8 MB. The animation works just fine on simulator and iPhone 4, but when I test on iPhone 3GS, the app crashes due to the animation.

I've tried using UIImage imageNamed:, but I read that using imageWithData might 开发者_开发技巧be faster, so I have this:

            NSString *imageName=[NSString stringWithFormat:@"fishBg_%i.png", i];
            NSString *fileLocation = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
            NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
            [animationArray addObject:[UIImage imageWithData:imageData]];

What can my problem be? When I reduce the number of frames to about 100, then the animation plays and the app doesn't crash. But when I bring up the frame count to 200, then the app crashes. What's a better way to do this? The animation is a PNG sequence of transparent images, so I'm not sure if I'd be able to convert this to a video and keep its transparency and place other images under it.


Since we need to conserve as much memory as possible here (assuming that’s why you’re crashing), try managing memory more explicitly:

NSString *imageName=[[NSString alloc] initWithFormat:@"fishBg_%i.png", i];
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
[imageName release];
UIImage *theImage = [[UIImage alloc] initWithContentsOfFile:fileLocation];
[animationArray addObject:theImage];
[theImage release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜