-(IBAction)duckAction:(id)sender{
CABasicAnimation *moveDuck = [CABasicAnimation animationWithKeyPath:@"position"];
[moveDuck setRemovedOnCompletion:YES];
[moveDuck setDuration:.40];
[moveDuck setRepeatCount:1];
[moveDuck setAutoreverses:NO];
[moveDuck setFromValue:[NSValue valueWithCGPoint:
CGPointMake(btnDuck.center.x+25 ,btnDuck.center.y)]];
[moveDuck setToValue:[NSValue valueWithCGPoint:
CGPointMake(btnDuck.center.x -25, btnDuck.center.y)]];
[btnDuck.layer addAnimation:moveDuck forKey:@"position"];
}
-(IBAction)frogAction:(id)sender{
ptFrog = btnFrog.center;
[UIView animateWithDuration:1.00
delay:0.0
options:(UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction)
animations:^ {
CGPoint position;
position.y = 577.0f;
position.x = 58.0f;
btnFrog.center = position;
}
completion:^(BOOL finished){
btnFrog.center = ptFrog;
}];
}
我有两个相互靠近的按钮。首先我按下青蛙按钮然后我在青蛙动画结束时按下鸭子按钮,青蛙按钮闪烁。我不知道为什么会这样?如何删除闪烁?
答案 0 :(得分:0)
在完成块dude中删除此行。
btnFrog.center = ptFrog;
动画完成后立即将其置于中心位置。这就是闪烁的原因。如果要设置中心,请将上面的代码放在动画块中
更新
-(IBAction)frogAction:(id)sender{
ptFrog = btnFrog.center;
[UIView animateWithDuration:1.00
delay:0.0
options:(UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction)
animations:^ {
CGPoint position;
position.y = 577.0f;
position.x = 58.0f;
//btnFrog.center = position;
btnFrog.center = ptFrog;
}
completion:^(BOOL finished){
}];
}