Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate UIView scale to zero

I am having trouble animating scale of a view to zero. Here's my code:

[UIView animateWithDuration:0.3 animations:^{
    myView.transform = CGAffineTransformMakeScale(0.0, 0.0);
} completion:^(BOOL finished){

}];

For some reason, the view stretches and squeezes horizontally like old TV tube switching off. If I make the scale to (0.1, 0.1) instead, it scales properly, but of course, not til zero.

Why is this happening?

like image 946
pixelfreak Avatar asked Oct 29 '11 06:10

pixelfreak


1 Answers

If someone is still interested, here's what I did (in Swift) to make it work (almost):

UIView.animate(withDuration: 1) {
    myView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
}

If the duration is short, you don't get to see that is doesn't scale exactly to 0 and it effectively fades.

like image 84
Skoua Avatar answered Sep 22 '22 21:09

Skoua