Search code examples
iosobjective-canimationuiimageview

Animate images in uiimageview


How to animate the images from web service. I got the code to animate the images from bundle.How to load the images from the url an array

That code is attached below

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"image1.gif"],
                               [UIImage imageNamed:@"image2.gif"],
                               [UIImage imageNamed:@"image3.gif"],
                               [UIImage imageNamed:@"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];

Solution

  • To download images from web service:

    NSData *imageData = [NSData dataWithContentsOfURL:"*Url from web service*"];
    UIImage *imageOne = [UIImage imageWithData:imageData];
    

    likely download all images from web service and create an array like:

    NSArray *imagesArray = [NSArray arrayWithObjects:imageOne...........,nil];
    

    and use with little modification:

    UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
    animatedImageView.animationImages = imagesArray;
    animatedImageView.animationDuration = 1.0f;
    animatedImageView.animationRepeatCount = 0;
    [animatedImageView startAnimating];
    [self.view addSubview: animatedImageView];