[英]Animation Grow/Decrease Size imageView iOS
我正在嘗試使用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);
}];
}];
這將使imageview最初尺寸減小,並且當動畫結束時,它將通過動畫恢復到其原始尺寸。
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)
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.