繁体   English   中英

为什么我的动画不起作用?

[英]why is my animations not working?

我有一个蓝色的小圆圈,可以淡入和淡出两个不同的位置,直到用户触摸屏幕为止。 然后,我希望圆在其所处的位置逐渐消失。

- (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方法上设置了延迟)。

正如ACB所指出的,要做的第一件事就是将Delay设置为零。 为了能够开始延迟淡入淡出,我建议使用计时器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM