質問

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.

役に立ちましたか?

解決 3

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.

他のヒント

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.

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).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top