Iphone 为图像按钮的移动和缩放设置动画

Iphone 为图像按钮的移动和缩放设置动画,iphone,uiimageview,uiimage,uibutton,Iphone,Uiimageview,Uiimage,Uibutton,我希望它是动画的,所以我使用的是[UIView beginAnimations] 我尝试过使用按钮.imageView.frame(图像设置为imageView)设置动画,但它只对位置设置动画,图像根本不会缩小 使用hateButton.frame(当图像设置为backgroundImage时),backgroundImage会缩小,但不会设置动画 如何设置缩放UIButton图像的动画?我可以使用Quartz 2D实现这一点: // move anchor point without movi

我希望它是动画的,所以我使用的是
[UIView beginAnimations]

我尝试过使用
按钮.imageView.frame
(图像设置为imageView)设置动画,但它只对位置设置动画,图像根本不会缩小

使用
hateButton.frame
(当图像设置为backgroundImage时),backgroundImage会缩小,但不会设置动画


如何设置缩放UIButton图像的动画?

我可以使用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];
确保也导入Quartz2D:

#import <QuartzCore/QuartzCore.h>
#导入

您可以在
[UIView beginAnimations]
[UIView commintAnimations]
之间或使用
[UIView animateWithDuration]
调用
layoutifneed

[UIView animateWithDuration:0.3f animations:^{
    self.myButton.frame = aFrame;    
    [self.myButton layoutIfNeeded];
 }];

通过将button.imageView.transform设置为CGAffineTransform,可以将转换直接应用于button.imageView。我决定改用UIImageView,因此可以使用正常的可设置动画的帧。然后我在上面放了一个看不见的按钮。