2013-03-22 31 views
0

我有一個簡單的爆炸動畫,可以在我班的任何方法中工作得很好。不過,我想在定時器更新方法用完定時器後調用它。問題在於,無論出於何種原因,它都不會在這裏工作(肯定會對計時器產生影響)。它只是取消隱藏我的形象..沒有動畫。我無法弄清楚如何讓它起作用。未開火的動畫

- (void)explosionAnimation 
{ 
    imgExplosion.hidden=FALSE; 

    //set starting point of explosion 
    CGRect explosionFrame = self.imgExplosion.frame; 
    explosionFrame.origin.x = explosionFrame.origin.y = -960.0f; 
    explosionFrame.size.width = explosionFrame.size.height = 1920.0f; 

    [UIView animateWithDuration:1.5f animations:^{ 
     self.imgExplosion.frame = explosionFrame; 
    } completion:^(BOOL finished) { 
     self.imgExplosion.hidden = YES; 
    }]; 
} 

-(void) createTimer 
{ 
    // Create timer instance 
    if (timer != nil){ 

     [timer invalidate]; 
     hasTimerStarted = NO; 
    } 

    // Initialize the timer. 
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 
              target:self 
              selector:@selector(timerUpdater) 
              userInfo:nil repeats:YES]; 
} 

- (void)timerUpdater{ 

    if(!hasTimerStarted){ 
     intTotalSeconds = [strTotalNumberofSeconds intValue]; 

     hasTimerStarted = YES; 
    } 
    else{ 
     intTotalSeconds--; 

     self.lblTimer.text = [self revertTimeToString:intTotalSeconds]; 
    } 

    // if totalSeconds hits zero, then time is up! You lose! 
    if (intTotalSeconds == 0){ 
     [timer invalidate]; 

     [self explosionAnimation]; 

     hasTimerStarted = NO; 

     [self addPlayAgainButton]; 
    } 
} 

回答

2

嘗試把一些延遲或致電爆炸方法在主線程上像

[self performSelector:@Selector(explosionAnimation) withObject:nil afterDelay:1.0]; 
+0

這會工作。謝謝! – mablecable 2013-03-22 03:59:24