我有一个蓝色的小圆圈,在用户触摸屏幕之前淡入淡出到两个不同的位置。然后我希望圆圈在它所在的位置淡出。
- (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 方法上设置的延迟)。