开发者

uibutton animation

开发者 https://www.devze.com 2023-02-17 11:18 出处:网络
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 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 :)


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

精彩评论

暂无评论...
验证码 换一张
取 消