-1

我使用这段代码来创建和运行计时器,它工作正常。

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];  

}

正如我上面所说,这只能正常工作一次,但不会重复!谢谢 :)

4

1 回答 1

1

startAnimating启动设置为运行一次的动画。你永远不会停止动画,所以发送一秒钟startAnimating什么都不做。尝试:

-(void)startAnimation {
    [myUIImageView stopAnimating];
    [myUIImageView startAnimating];
}
于 2012-08-31T14:12:12.137 回答