Animating UIButton move and zoom
I want it to be animated, so I use [UIView beginAnimations]
I tried animating with button.imageView.frame
(with image set as imageView) but it only animates the position, the image doesn't shrink at all.
using hateButton.frame
(when the image is set as backgroundImage), the backgroundImage is scaled down but not animated.
How to enlarge UIButton image for animation?
+2
source to share
2 answers
I could achieve this using Quartz 2D:
// move anchor point without moving frame
CGRect oldFrame = hateButton.frame;
hateButton.layer.anchorPoint = CGPointMake(0, 1); // bottom left
hateButton.frame = oldFrame;
[UIView beginAnimations:nil context:NULL];
CGAffineTransform newTransform;
newTransform = CGAffineTransformMakeScale(0.8, 0.8);
hateButton.transform = CGAffineTransformTranslate(newTransform, 0, -160);
[UIView commitAnimations];
Make sure you import Quartz2D as well:
#import <QuartzCore/QuartzCore.h>
+3
source to share