简体   繁体   English

UIImageView中的gif动画

[英]Animated gif in UIImageView

I want to show an animated ".gif" in a ImageView . 我想在ImageView显示动画的“ .gif”。 Now I managed it like here: click with UIImage+animatedGIF . 现在,我按如下所示进行管理: 单击 UIImage+animatedGIF But if it begins to animate 2 gifs it uses 45Mb of memory I think that is very much for 2 gif's with 100kb. 但是,如果它开始制作2个gif动画,它将使用45Mb的内存,我认为这对于2 gif的100kb内存非常有用。 What can I do? 我能做什么? Code to start animation here: 在此处开始动画的代码:

NSString *path = [[NSBundle mainBundle]pathForResource:@"animation" ofType:@"gif"];             
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];         
_testImage.image = [UIImage animatedImageWithAnimatedGIFURL:url];         
_test1.image = [UIImage animatedImageWithAnimatedGIFURL:url]; 

I had same issue while adding animating images on UIScrollView. 在UIScrollView上添加动画图像时遇到相同的问题。 Use FLAnimatedImageView. 使用FLAnimatedImageView。 https://github.com/Flipboard/FLAnimatedImage https://github.com/Flipboard/FLAnimatedImage

IT works like magic. IT就像魔术一样工作。 :) :)

Try this 尝试这个

    // Load images
    NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.png", @"win_4.png",
                        @"win_5.png", @"win_6.png", @"win_7.png", @"win_8.png",
                        @"win_9.png", @"win_10.png", @"win_11.png", @"win_12.png",
                        @"win_13.png", @"win_14.png", @"win_15.png", @"win_16.png"];

    NSMutableArray *images = [[NSMutableArray alloc] init];
    for (int i = 0; i < imageNames.count; i++) 
    {
        [images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
    }

    // Normal Animation
    UIImageView *animationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(60, 95, 86, 193)];
    animationImageView.animationImages = images;
    animationImageView.animationDuration = 0.5;

    [self.view addSubview:animationImageView];
    [animationImageView startAnimating];

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

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