Leon
Leon

Reputation: 417

uibutton animation

is there a possibility to animate an uibutton in this way that a thing or whatever comes out of the background e.g. a wheat ear comes out of a field.

is this possible?

thanks :)

Upvotes: 3

Views: 4104

Answers (1)

Ned
Ned

Reputation: 6270

Unless you want a more complicated animation, you can just create a custom type UIButton (either with IB by changing the type to Custom, or programmatically with UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]), then set the button's image with [aButton setImage:[UIImage imageNamed:@"wheat_ear" forState:UIControlStateNormal].

To move it, just animate its position normally...

[UIView animateWithDuration:0.5 animations:^{aButton.center = newCenter;}];

Or, to provide the illusion of it coming out of the field, animate the bounds of the image so that it starts with the image's width and zero height, and ends with the image's width and height:

CGRect originalFrame = aButton.frame;
aButton.frame = CGRectMake(originalFrame.origin.x, originalFrame.origin.y, originalFrame.size.width, 0);
[UIView animateWithDuration:0.5 animations:^{aButton.frame = originalFrame;}];

Upvotes: 7

Related Questions