Uibutton animation

Is it possible to animate uibutton in such a way that a thing or something else comes out of the background, for example. ear of wheat comes out of the field.

Is it possible?

thank:)

+3
source share
1 answer

If you don’t need a more complex animation, you can simply create a custom UIButton type (either with IB, changing the type to Custom, or programmatically with UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom]), then set the button 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 his way out of the field, animate the borders of the image so that it starts with the width of the image and zero height and ends with the width and height of the image:

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

All Articles