我使用这段代码来创建和运行计时器,它工作正常。
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];
我的 startAnimation 方法只包含
[myUIImageView startAnimating];
该方法确实每六秒运行一次,但动画运行一次并且不重复。
任何想法为什么会发生这种情况?
编辑。我的动画是这样设置的:
-(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];
}
正如我上面所说,这只能正常工作一次,但不会重复!谢谢 :)