动画没有开火

时间:2013-03-22 03:33:20

标签: ios objective-c animation

我有一个简单的爆炸动画,可以在我班级的任何方法中正常工作。但是,一旦定时器用完,我想从定时器更新方法调用它。问题是,无论出于何种原因它都无法在这里工作(肯定会与计时器有关)。它只是取消隐藏我的形象..没有动画。我无法弄清楚如何让它发挥作用。

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

1 个答案:

答案 0 :(得分:2)

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

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