我开始学习使用UIView动画.所以我写了以下几行:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.0];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];
CGPoint position = greenView.center;
position.y = position.y + 100.0f;
position.x = position.x + 100.0f;
greenView.center = position;
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,UIView(一个绿色的盒子)向后移动了2次.到目前为止一切都那么好,但我发现在移动两次后,绿色框最终跳到"新位置"(position.x + 100.0f,position.y + 100.0f)而不是回到原来的位置(position.x,position.y).这使得动画看起来很奇怪(就像在setAnimationRepeatAutoreverses引起的回弹到原始位置之后,它会在最后一微秒内跳回到新的位置!)
什么是让绿箱不会在最后一分钟跳到新位置的最佳方法?