我有一个蓝色的小圆圈,在用户触摸屏幕之前会向两个不同的位置淡入淡出。然后我希望圆圈在它所处的位置淡出。
- (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方法上的延迟)。
答案 0 :(得分:1)
如ACB所示,首先要做的是将延迟设置为零。能够启动 延迟淡出我建议使用计时器。