Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动画不发射_Ios_Objective C_Animation - Fatal编程技术网

Ios 动画不发射

Ios 动画不发射,ios,objective-c,animation,Ios,Objective C,Animation,我有一个简单的爆炸动画,在我的类中的任何方法中都可以很好地工作。但是,我想在计时器用完后,通过计时器更新方法调用它。问题是无论出于什么原因,它都无法从这里开始工作(肯定与计时器有关)。它只是把我的形象隐藏起来。。没有动画。我想不出如何让它工作 - (void)explosionAnimation { imgExplosion.hidden=FALSE; //set starting point of explosion CGRect explosionFrame = s

我有一个简单的爆炸动画,在我的类中的任何方法中都可以很好地工作。但是,我想在计时器用完后,通过计时器更新方法调用它。问题是无论出于什么原因,它都无法从这里开始工作(肯定与计时器有关)。它只是把我的形象隐藏起来。。没有动画。我想不出如何让它工作

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

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

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