2012-08-31 23 views
0

我使用此代碼創建並運行計時器,該計時器工作正常。使用計劃的計時器在iOS中重複觸發動畫

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

} 

正如我前面所說,這工作正常只有一次,但後來不重複! 謝謝:)

+0

我沒有看到上面的代碼有任何問題......它可能與您的動畫代碼有關。你可以發佈嗎? – LonelyDeveloper

+0

你能提供動畫的代碼嗎? –

+0

@LonelyDeveloper添加到OP!乾杯。 –

回答

1

startAnimating開始設置運行一次的動畫。你永遠不會停止動畫,所以發送第二個startAnimating什麼都不做。嘗試:

-(void)startAnimation { 
    [myUIImageView stopAnimating]; 
    [myUIImageView startAnimating]; 
} 
+0

啊!耶穌。我知道這件事很簡單。你是一個天才,我是一個白癡。謝謝。 –

+0

沒關係。儘量讓你的物體儘可能體面。 –