I use this code to create and run the timer, which works OK.
NSDate *d = [NSDate dateWithTimeIntervalSinceNow: 6.0];
NSTimer *t = [[NSTimer alloc] initWithFireDate: d
interval: 6
target: self
selector:@selector(startAnimation)
userInfo:nil repeats:YES];
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:t forMode: NSDefaultRunLoopMode];
My startAnimation method just contains
[myUIImageView startAnimating];
The method does run every six seconds, but the animation runs once and does not repeat.
Any ideas why this is happening?
Edit. My animation is set up like this:
-(void) setUpAnimation{
myUIImageView = [[UIImageView alloc] initWithFrame:self.animatedView.frame];
myUIImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],
[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],
nil];
myUIImageView.animationDuration = 3;
myUIImageView.animationRepeatCount = 1;
//add the animation view to the main window;
[self.view addSubview:myUIImageView];
}
As I said above, this works fine just once, but then does not repeat!
Thanks 🙂
startAnimatingstarts the animation that is set up to run one time. You never stop the animation, so sending a secondstartAnimatingdoes nothing. Try: