简体   繁体   English

第一次图像动画需要很长时间进行动画处理

[英]First time Image animation takes long time to animating

In my application there is animation of 260 images with dimension 640*1136 of .jpg file.I load all images in array as below. 在我的应用程序中,有260张图像的动画 .jpg文件的尺寸为640 * 1136。我将所有图像加载到数组中,如下所示。

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 它将分配初始化我的数组,并从资源文件夹中加载所有260张图像

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 对于Image动画,仅使用该数组并将其传递给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. 注意 :我发现很多帖子都与此问题相关,但是没有一个可以帮助我解决此问题。

You have to do this [self initSingArray]; 您必须执行此操作[self initSingArray]; in viewDidLoad or other place rather then on button click. viewDidLoad或其他位置,而不是在按钮上单击。 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 . 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. 最重要的是,您永远不会使用animationImages方法和许多类似的图像来使您的应用程序正常工作。 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). 您最好使用已经解决内存问题的现有解决方案,并提供一种避免在动画开始显示之前将所有图像数据解码到内存中的方法(这就是为什么开始动画如此缓慢的原因)。

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 而不是使用UIImageView进行动画播放请尝试使用此炉排教程Memory_usage_on_ios

and simplified PNG animation example code 简化的PNG动画示例代码

Hope this answer will help someone to animate lots of image frames without memory leak issues. 希望此答案可以帮助某人为许多图像帧设置动画,而不会出现内存泄漏问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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