移动UIButton位置,动画 [英] Moving UIButton position, animated
问题描述
我有一个UIButton,按下它时我想移动它的位置。
I have a UIButton, which when it's pressed I want to move the position of it.
我已经通过以下代码做到了这一点:
I've managed to do this by this code:
ans2.frame = CGRectOffset(ans2.frame, 0, 20);
但是,这只是立即移动按钮。
However this just moves the button instantly.
我也尝试过通过将++移至新位置来移动它,但这看起来像是动画滞后。
I've also tried just moving it by doing ++ to the position until the new one is reached, however this makes it look like the "animation" lags.
是否可以使用平滑的动画来移动按钮?
Would it be possible to move the button with a smooth animation?
推荐答案
UIKit提供了几种执行动画的方法。在您的情况下,最简单的方法是:
UIKit provides several ways to perform animations. The simplest way in your case would be this:
[UIView animateWithDuration:1.0 animations:^{
ans2.frame = CGRectOffset(ans2.frame, 0, 20);
}];
但是,还有很多其他动画效果。结帐 Apple的动画指南。
However, there are plenty of other possibilities to animate. Checkout Apple's Animation Guide.
这篇关于移动UIButton位置,动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!