简体   繁体   中英

iOS - UIImageView Animation receiving memory warning

I am attempting to run two UImageViews that have multiple arrays of animations they load and animate based on a selection the user makes. For example, here is one method:

-(void)initiateAnimations {

nullAnimation = [NSArray arrayWithObjects:

          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0002" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0003" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0004" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0005" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0006" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0007" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0008" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0009" ofType:@"png"]],
          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"null0010" ofType:@"png"]], nil];
}

And here is an IBAction calling the animation method:

-(IBAction)nullani {
player.animationImages = nullAnimation;
player.animationDuration = 0.50;
player.animationRepeatCount = 1;
[player startAnimating];
}

It all works well at first, but keep in mind i have about 5-6 other arrays of animations roughly with the same size images. They arent huge, ranging from 12-80k .png files. When i attempt to animate after a few times, I am recieving this error in the output:

2013-03-16 01:34:44.438 [3316:907] Received memory warning.

After i receive this message, any new animation loaded will crash the app. I ran it through Instruments and was unable to find any leaks, and the output gives me nothing upon crash.

Is there any memory issues here? how can i get rid of this issue? thanks.

Some ideas:

1) Never have more than 1 animation loaded into an array. Once you stop one animation, and are ready to start another, delete the first animation and replace the image the viewer sees with the single image that should be showing. If you can determine the exact image that was showing (and am doubtful of this) then you can replace the array with a single image and the image will not flicker.

2) If you cannot do 1), then try using Core Animation directly (more work for you), and do the animation yourself. This gives you more control over memory usage (you could cache image bitmaps on the file system).

3) Using a Mac and AVFoundation or QTKit, make an animation from images, then create a "movie" that you start and stop instead of the image sequence. In this case you'd replace the static images in the bundle with movie objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM