Question

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

No correct solution

OTHER TIPS

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.

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)
    })
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top