我想让UIButton
图像从当前大小变换为其大小的两倍,然后再回到原始大小,类似于facebook“喜欢”动画。
我正在使用此代码但由于某种原因它正在执行相反的操作;即先缩小,然后再变大。
我做错了什么?它适用于uiimageView
,但不适用于uibutton
[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;
}];
}];
答案 0 :(得分:1)
图层有一个属性masksToBounds
,UIView有clipsToBounds
。很可能按钮在主视图或子视图上将这些设置为YES。您可以发现哪些设置为YES,并将它们暂时设置为NO。
答案 1 :(得分:1)
如果有人有兴趣我通过在按钮上方添加uiimageview并为其设置动画而不是按钮图像来解决它。
它是一个黑客但它的工作。
答案 2 :(得分:0)
//设置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);
}];
}];
//试试这个