I have a UImageViewwhich i have set up in interface builder with a png (pair of eyes) from my resources. I then want to replace this image (after a specific amount of time) with an animation of eyes blinking.
This is the code i have used which is called in viewWillAppear:
NSString *fileName;
NSMutableArray *imageArray = [[NSMutableArray alloc] init];
for(int i = 1; i < 12; i++) {
fileName = [NSString stringWithFormat:@"HDBlinkPage1/hd_eyes_blinking%d.png", i];
[imageArray addObject:[UIImage imageNamed:fileName]];
}
imgHDBlink.userInteractionEnabled = YES;
imgHDBlink.animationImages = imageArray;
imgHDBlink.animationDuration = 0.9;
imgHDBlink.animationRepeatCount = 1;
imgHDBlink.contentMode = UIViewContentModeScaleToFill;
//[self.view addSubview:imgHDBlink];
[imgHDBlink startAnimating];
In viewWillAppear I use an NSTimer to trigger the animation every 5 seconds:
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(blinkAnimation)
userInfo:nil
repeats:YES];
The problem is, when i run the application i don’t see the initial static image at all. I just see the animation every 5 seconds but no image of the open eyes in between these animations. Can anyone please help me resolve this issue or point me in the right direction? Thanks.
Add the animation images after 5.0 seconds. From the UIImageView docs:
If you set the animationImages array beforehand, it won’t display the image.
EDIT:
(All using ARC)