RGriffiths
RGriffiths

Reputation: 5970

Loading animated gif in iPad app

I have use the following code for displaying a loading animated gif however it does not appear to be working properly. The NSArray is correctly loaded with the set of images and the first image loads but no animation occurs (the images are different). Can anyone point out my mistake?

.h file

@property (strong, nonatomic) IBOutlet UIImageView *loadingGif; .m file

@synthesize loadingGif;

...

[loadingGif setAlpha: 1];
NSArray *imageArray = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"g0.png"], [UIImage imageNamed:@"g1.png"], [UIImage imageNamed:@"g2.png"], [UIImage imageNamed:@"g3.png"], [UIImage imageNamed:@"g4.png"], [UIImage imageNamed:@"g5.png"], nil];
loadingGif = [[UIImageView alloc] initWithFrame:CGRectMake(435, 441, 152, 14)];
loadingGif.animationImages = imageArray;
loadingGif.animationDuration = 1.5;
loadingGif.contentMode = UIViewContentModeScaleAspectFill;
[loadingGif startAnimating];

Upvotes: 0

Views: 336

Answers (1)

Seamus
Seamus

Reputation: 243

because

loadingGif = [[UIImageView alloc] initWithFrame:CGRectMake(435, 441, 152, 14)];

you init a new UIImageView instance, not init in your xib.

And you don't add to view. like [self.view addSubView:loadingGif];

Upvotes: 1

Related Questions