0

ユーザーが画面に触れるまで、2 つの異なる場所にフェードインおよびフェードアウトする小さな青い円があります。次に、円がその位置でフェードアウトするようにします。

- (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 が最初にすべきことは、Delay をゼロに設定することです。遅延フェードアウトを開始できるようにするには、タイマーを使用することをお勧めします。

于 2012-11-20T06:07:28.617 に答える