Animate move and scale of image UIButton
I want it to be animated so I'm using [UIView beginAnimations]开发者_StackOverflow中文版
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?
You can call layoutIfNeeded
between [UIView beginAnimations]
and [UIView commintAnimations]
or with [UIView animateWithDuration]
.
[UIView animateWithDuration:0.3f animations:^{
self.myButton.frame = aFrame;
[self.myButton layoutIfNeeded];
}];
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>
精彩评论