0

我有一个蓝色的小圆圈,在用户触摸屏幕之前淡入淡出到两个不同的位置。然后我希望圆圈在它所在的位置淡出。

- (void)fadePowerUpOut {

    [UIView animateWithDuration:.5 delay:2 options:UIViewAnimationOptionCurveLinear animations:^{//the power up will stay in its position until after 2 seconds it will fade out which is because of the delay
        self.powerUp.alpha=0;
    } completion:^(BOOL finished) {
        if (finished) {//I put if finished here because i don't want this method to be ran if the user touches the screen within the 2 second delay
            if (self.powerUp.frame.origin.x==self.rectPowerUp.origin.x) {//if its in the first location go to the second
                self.powerUp.frame=self.rectPowerUp2;

            }else{//if its in the second location go to the first 
                self.powerUp.frame=self.rectPowerUp;
            }
            [self fadePowerUpIn];
        }
    }];
}

- (void)fadePowerUpIn {
    [UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
        self.powerUp.alpha=1;
    } completion:^(BOOL finished) {
        if (finished) {
              [self FadePowerUpOut];
        }   
    }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

     [UIView animateWithDuration:.5 delay:0 options:UIViewAnimationCurveLinear|UIViewAnimationOptionBeginFromCurrentState animations:^(){ self.powerUp.alpha=0;} completion:^(BOOL completion){
  }];
}

发生的事情是,当用户触摸屏幕时,圆圈不会淡出,而只会在 2 秒后淡出(我在 fadePowerUpOut 方法上设置的延迟)。

4

1 回答 1

1

正如 ACB 所指出的,首先要做的是将延迟设置为零。为了能够开始延迟淡出,我建议使用计时器。

于 2012-11-20T06:07:28.617 回答