2

I'm using a custom created loading spinner for my iOS app, but the edges looks rough on a coloured background as expected from a GIF.

How do other apps handle this situation? Do they use anything other than GIF, maybe APNG or something? Cause with GIF, the edges are always going to be rough, if matte is used, it would look good on just one color and not the others.

Any solution?

Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
eozzy
  • 66,048
  • 104
  • 272
  • 428
  • 1
    Bottom line... don't use GIF, if you have GIF images you simply must use, convert them to PNG at build or development time. – David Berry May 09 '14 at 21:11
  • You can convert animated GIFs to APNG and then load the animated image series with a full alpha channel using AVAnimator https://stackoverflow.com/questions/25074340/avanimator-mvid-conversion/25478854#25478854 – MoDJ Jun 05 '15 at 23:18

1 Answers1

4

The UIImageView class provides the easiest way for developers to implement animations. All you need to do is to create an UIImageView object with a series of images for animating.

Example

// Load images
NSArray *imageNames = @[@"win_1.png", @"win_2.png", @"win_3.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];
Community
  • 1
  • 1
Rafał Sroka
  • 39,540
  • 23
  • 113
  • 143
  • 1
    This is "easy" but it will not actually work well. If you load up a lot of images then you can crash the app and even the entire device due to runaway memory usage. This animationImages approach should not be used in a real app. – MoDJ Jun 05 '15 at 23:20
  • I can't add NSMutableArray of images to UIImageView. Instead I added as an array of UIImage. – Thamarai T Aug 07 '19 at 05:55