0

In my application there is animation of 260 images with dimension 640*1136 of .jpg file.I load all images in array as below.

On button click

- (void)singButtonClick:(id)sender
{
    [self initSingArray];
    [self startAnimationWithImages:singArray duration:2];
}

It will alloc init my Array, and Load all 260 images from resource folder

self.imageArray = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];


- (void)initSingArray
{
    if (!singArray)
    {
        singArray=[[NSMutableArray alloc] init];

        for(NSString *str in self.imageArray)
        {
            if([[str lastPathComponent] hasPrefix:@"Sing_"])
            {
                [singArray addObject:[UIImage imageNamed:[str lastPathComponent]]];
            }
        }
    }
}

and for Image animation simply used that array and passed it to to UIImageView

- (void)startAnimationWithImages:(NSMutableArray*)images duration:(NSTimeInterval)duration
{
    [self startAnimationWithImages:images duration:duration repeatCount:1];
}

- (void)startAnimationWithImages:(NSMutableArray*)images duration:(NSTimeInterval)duration repeatCount:(int)repeatCount
{
    if (self.gifImageView.isAnimating) 
    {
        [self.gifImageView stopAnimating];
    }

    self.gifImageView.animationImages = nil;
    self.gifImageView.animationImages = images;          // Animated image array
    self.gifImageView.animationDuration = duration;      // Perform a full animation when
    self.gifImageView.animationRepeatCount = repeatCount;// Animation number of repetitions
    [self.gifImageView startAnimating];
}

but when clicked on button at FIRST time it will takes long time to animating.It will works fine when there are LESS number of images.

Is the dimension of images will create problem?

Please help me to solve it out.

NOTE: I found many post related this questions but none of them is help me to resolve this problem.

Harin
  • 867
  • 11
  • 23
  • well, all these images have to be loaded to memory before they can be displayed. When you have less images, this process takes less time (obviously). You have to preload your images. You say related posts didn't help with your problems - why? Do you not want to preload images? – Kreiri Jun 11 '13 at 10:35
  • @Kreiri: yes, i Preload all images but on button click it will takes time for animating. and one more thing when i click on next button for another animation(load other images in another ARRAY) it will be crash. – Harin Jun 11 '13 at 11:03
  • And that second crash is surely because you ran out of memory. – Kreiri Jun 11 '13 at 13:50
  • @Kreiri : I thinks it will be.Actually I m creating App like Talking Tom so i have to used many images for animation.So Can you help me for solution? Thanks for your reply – Harin Jun 12 '13 at 06:29
  • Not really. You'll have to rethink your design. – Kreiri Jun 12 '13 at 09:08

3 Answers3

0

You have to do this [self initSingArray]; in viewDidLoad or other place rather then on button click. it will solve your problem. The reason in your case is at first time the image array is created so it takes time.

Prateek Prem
  • 1,544
  • 11
  • 14
0

See my answer to the same sort of question at imageview-animation-getting-more-memory. The bottom line is that you are never going to get your app to work using the animationImages approach and lots of images like you have. You are better off using an existing solution that already deals with the memory issues and provides a way to avoid decoding all the image data into memory before the animations begin to display (which is why it is so slow to begin animating).

Community
  • 1
  • 1
MoDJ
  • 4,309
  • 2
  • 30
  • 65
0

After lots of R&D Finally i resolve this issue with some grate blog-post.My application is successfully working without crashing issues and with fast response.

Instead of using UIImageView for animating Try this grate Tutorial Memory_usage_on_ios

and simplified PNG animation example code

Hope this answer will help someone to animate lots of image frames without memory leak issues.

Harin
  • 867
  • 11
  • 23