Animation Grow/Decrease Size imageView iOS

user1708257 picture user1708257 · Oct 8, 2013 · Viewed 18.2k times · Source

I'm trying to animate a custom button using CGAffineTransformMakeScale as follows:

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;
    }];
}   

The button grows perfectly to the original size, however, i don't know the reason but when i click on the button to decrease it, it decreases from a size like 100% bigger than the original size to the original size, instead of beginning the decrease in the original size and achieve an scale of 0.01 as I indicated in the code.

Please help!!

Answer

Geekoder picture Geekoder · Oct 8, 2013

You can animate the grow and decrease size of the image view using the following code

[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);    
    }];
}];

This will make the imageview decrease in size initially and when animation is over it will get back to its original size with an animation.