user7184
user7184

Reputation: 13

Moving UIButton position, animated

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?

Upvotes: 1

Views: 3338

Answers (1)

croX
croX

Reputation: 1725

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);
}];

However, there are plenty of other possibilities to animate. Checkout Apple's Animation Guide.

Upvotes: 4

Related Questions