简体   繁体   中英

uibutton animation

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

is this possible?

thanks :)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM