Using an animated gif in iOS

Kite gif

You can’t use gif’s in iOS but you can do the same thing with a series of png’s. Here’s the code that I use to put a kite on the screen and then animate the tail.

- (void)animatedReward {
    UIImageView *staticView = [[UIImageView alloc] initWithFrame:self.view.frame];
    staticView.image = [UIImage imageNamed:@"kite.png"];
    [self.view addSubview:staticView];
    
    NSArray *imagesArray = [NSArray arrayWithObjects:[UIImage imageNamed:@"kite-tail1.png"], [UIImage imageNamed:@"kite-tail2.png"], [UIImage imageNamed:@"kite-tail3.png"], [UIImage imageNamed:@"kite-tail2.png"], [UIImage imageNamed:@"kite-tail1.png"], nil];
   
    UIImageView *animatedView = [[UIImageView alloc] initWithFrame:staticView.frame];
    
    animatedView.animationImages = imagesArray;
    animatedView.animationDuration = 1;
    [animatedView startAnimating];
    [self.view addSubview:animatedView];
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.