简体   繁体   English

使UIButton imageView比框架更大,然后回到原来的尺寸?

[英]make a UIButton imageView Bigger than the frame and then back to its original size?

I want to make the UIButton image transform from its current size to twice its size and then back to its original size similar to the facebook "like" animation. 我想让UIButton图像从当前大小转换为其大小的两倍,然后回到原始大小,类似于facebook“like”动画。

I'm using this code but for some reason it is doing the reverse action; 我正在使用此代码但由于某种原因它正在执行相反的操作; ie first shrinks and only then getting large again. 即先缩小,然后再变大。

What am I doing wrong? 我究竟做错了什么? It works perfectly on a uiimageView but not on a uibutton 它在uiimageView上运行完美,但在uibuttonuiimageViewuibutton

[self.likeButton setClipsToBounds:NO];
CGAffineTransform firstTransform = self.likeButton.imageView.transform;
[UIView animateWithDuration:.15f animations:^{

    self.likeButton.imageView.transform = CGAffineTransformScale(firstTransform, 2, 2);

} completion:^(BOOL finished) {

    [UIView animateWithDuration:.15f animations:^{

        self.likeButton.imageView.transform = firstTransform;
    }];
}];

Layers have a property masksToBounds and UIView has clipsToBounds . 图层具有属性masksToBounds和UIView具有clipsToBounds Most likely the button has these set to YES on the primary view or subviews. 很可能按钮在主视图或子视图上将这些设置为YES。 Its possible you can discover which ones have these set to YES, and set them temporarily to NO. 您可以发现哪些设置为YES,并将它们暂时设置为NO。

If anyone is interested I solved it by adding a uiimageview above the button and animate it instead of the button image. 如果有人有兴趣我通过在按钮上方添加uiimageview并对其进行动画处理而不是按钮图像来解决它。

its a hack but its working. 它是一个黑客但它的工作。

//set button.masktobound=NO //设置button.masktobound = NO

[UIView animateWithDuration:.15f animations:^{

 self.likeButton.imageView.transform = CGAffineTransformMakeScale(2.0,2.0);

} completion:^(BOOL finished) {

[UIView animateWithDuration:.15f animations:^{

    self.likeButton.imageView.transform = CGAffineTransformMakeScale(1.0,1.0);
}];
}];

//Try this //尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM