Pregunta

I want to show an animated ".gif" in a ImageView. Now I managed it like here: click with 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. 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]; 
¿Fue útil?

Solución 2

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];

Otros consejos

I had same issue while adding animating images on UIScrollView. Use FLAnimatedImageView. https://github.com/Flipboard/FLAnimatedImage

IT works like magic. :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top