Basically, I have a UIImageView that will loop through 8 PNGs over 0.5 seconds. At the same time I start the animation, I do a performSelector with afterDelay of 0.5 seconds. So after my UIImageView has finished animating it will call animationTickDone which will set the last image hidden to no.
Here’s the code anyway:
.h
@interface ViewController : UIViewController{
IBOutlet UIView *scannedView;
IBOutlet UIImageView *animatedTickLast;
}
@property (nonatomic, retain) IBOutlet UIView *scannedView;
@property (nonatomic, retain) IBOutlet UIImageView *animatedTickLast;
.m
-(void)Found{
[self.view addSubview:scannedView];
[animatedTickLast setHidden:YES];
//place animated tick images into an array
NSMutableArray *animatedTickImages;
animatedTickImages = [[NSMutableArray alloc] init];
NSUInteger nimages = 0;
for (nimages=0; nimages<8; nimages++){
NSString *tickImageName = [NSString stringWithFormat:@"tick_%d.png", (nimages + 1)];
[animatedTickImages addObject:[UIImage imageNamed:tickImageName]];
}
//set up animated tick
UIImageView *animatedTick = [[UIImageView alloc] initWithFrame:CGRectMake(98, 213, 125, 90)];
[animatedTick setAnimationImages:animatedTickImages];
[animatedTick setAnimationDuration:0.5];
[animatedTick setAnimationRepeatCount:1];
[animatedTick startAnimating];
NSLog(@"animation started");
[self performSelector:@selector(animationTickDone) withObject:nil afterDelay:0.5];
[scannedView addSubview:animatedTick];
NSLog(@"animation added into view");
[animatedTickImages release];
}
- (void)animationTickDone{
NSLog(@"delay function begins");
[animatedTickLast setHidden:NO];
sleep(1); //sleep so that scannedView stays on screen for at least 1.5 seconds (0.5 after animation + 1 from sleep);
}
Now, the problem. The animation itself is fine, and works great. But when Found() is first called, animatedTickLast will become visible after the animation. But when ever Found is called again afterwords, animatedTickDone never appears again, it’s just an empty space.
After hours looking around the web searching and playing with it, I just cannot understand what the issue is as to why it doesn’t appear. I thought at one point sleep() was getting called before my animatedTickLast could get chance to set hidden to no, but after removing sleep() it still didn’t work.
Driving me nuts now so any help is greatly appreciated.
Thanks!
If I understand you correctly you want an image after the animaton in the UIImageView. Just set the image before the animation and you are fine!