Animation Grow/Decrease Size imageView iOS
Asked Answered
M

2

21

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!!

Morrill answered 8/10, 2013 at 12:10 Comment(0)
Y
34

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.

Youth answered 8/10, 2013 at 13:29 Comment(0)
F
20

SWIFT 3 Version

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)
    })
})
Fabricate answered 28/2, 2017 at 7:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.