views:

377

answers:

1

I want it to be animated so I'm using [UIView beginAnimations]

I've tried animating using button.imageView.frame (with image set as imageView) but it only animates the position, the image doesn't get scaled down at all.

using hateButton.frame (when image is set as backgroundImage), the backgroundImage gets scaled down but it's not animated.

How do I animate-scale a UIButton image?

A: 

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 too:

#import <QuartzCore/QuartzCore.h>
Sam V