2013-10-08 18 views
15

を下げる/成長:アニメーションは、私は次のようにCGAffineTransformMakeScaleを使用してカスタムボタンをアニメーション化しようとしているサイズImageViewのiOSの

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のスケールになります。

助けてください!

答えて

25

あなたが成長をアニメーション化し、次のコード

[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の減少を行いますと、アニメーションがその上にあるときに元のサイズになりますを使用して画像ビューのサイズを小さくすることができますアニメーション。

+0

素晴らしい親愛なります! –

6

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) 
    }) 
}) 
関連する問題