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

1 回答 1

2

尝试在主线程上放置一些延迟或调用爆炸方法,例如

[self performSelector:@Selector(explosionAnimation) withObject:nil afterDelay:1.0];
于 2013-03-22T03:48:58.240 回答