Im trying to make a animation with pictures using this code:
NSMutableArray *imageArray = [[NSMutableArray alloc] initWithCapacity:22];
int i;
for (i =1; i < 22; i++) {
[imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"fbAnimation%d.png", i]]];
//make it animate
self.fbLogin.animationImages = [NSArray arrayWithArray:imageArray];
self.fbLogin.animationDuration =0.8;
self.fbLogin.animationRepeatCount = 5;
[self.fbLogin startAnimating];
}
int j;
NSMutableArray *imageLoading = [[NSMutableArray alloc] initWithCapacity:4];
for (j = 1; j < 4; j++) {
[imageLoading addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading%d.png", j]]];
//make it animate
self.fbLogin.animationImages = [NSArray arrayWithArray:imageLoading];
self.fbLogin.animationDuration = 1;
self.fbLogin.animationRepeatCount = 5;
[self.fbLogin startAnimating];
}
}
The problem is that either way I’ve tried it so far just one animation gets executed on the screen. I want the first animation to run and then the second “Loading…” until all other data from facebook is ready.
Firstly, you are calling
[self.fbLogin startAnimating]and resetting theanimationImagesarray each time you go round eachforloop. You should move them outside the loops – you only need to start each animation once.Secondly, the second for loop will be executed immediately after the first, so the result I would expect would be for the second animation to appear, and not the first.
One way of getting round the problem would be to put the code for the second animation in a separate method, and then arrange for it to be called after the first has finished by calling:
at the end of the first
forloop. I’m assuming that since this is animation code we’re guaranteed to be on the main thread.