我正在尝试使用CGAffineTransformMakeScale对自定义按钮进行动画处理,如下所示:
if (stateButton == 0) { //The button is gonna appear
self.selected = YES;
self.imageView.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
// animate it to the identity transform (100% scale)
self.imageView.transform = CGAffineTransformIdentity;
} completion:nil];
}
else if (stateButton ==1) { //The button is gonna disappear
self.imageView.transform = CGAffineTransformMakeScale(1, 1);
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
// decrease button
self.imageView.transform = CGAffineTransformMakeScale(.01, .01);
} completion:^(BOOL finished){
self.selected = NO;
}];
}
按钮完美地增长到原始大小,但是,我不知道原因,但是当我单击按钮减小它时,它从比原始大小大 100% 的大小减小到原始大小,而不是开始减小原始大小并实现我在代码中指示的 0.01 的比例。
请帮忙!!
您可以使用以下代码对图像视图的大小进行动画处理
[UIView animateWithDuration:2.0 animations:^{
self.imageView.transform = CGAffineTransformMakeScale(0.5, 0.5);
}
completion:^(BOOL finished){
[UIView animateWithDuration:2.0 animations:^{
self.imageView.transform = CGAffineTransformMakeScale(1, 1);
}];
}];
这将使图像视图最初减小大小,当动画结束时,它将通过动画恢复到其原始大小。
SWIFT 3 版本
UIView.animate(withDuration: 2.0, animations: {() -> Void in
self.imageView?.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
}, completion: {(_ finished: Bool) -> Void in
UIView.animate(withDuration: 2.0, animations: {() -> Void in
self.imageView?.transform = CGAffineTransform(scaleX: 1, y: 1)
})
})