我有一个蓝色的小圆圈,淡入和淡出两个不同的位置,直到用户触摸屏幕为止。然后,我希望圆在其所处的位置逐渐消失。
- (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设置为零。为了能够开始
延迟淡入淡出,我建议使用计时器。
关于iphone - 为什么我的动画不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13466063/