Sagar Patel
Sagar Patel

Reputation: 197

UIView animateWithDuration jumps to final transform without animation

I have the following code to create flip transition. The fromView does not animate the transform and jumps to the final value but the toView correctly animates transform. What could be wrong here?

  toView.hidden = NO;
  toView.transform = CGAffineTransformMake(0, 0, 0, 1, 0, 0);
  [UIView animateWithDuration:0.4
                   animations:^{
                     fromView.transform = CGAffineTransformMake(0, 0, 0, 1, 0, 0);
                   }
                   completion:^(BOOL finished) {
                     fromView.hidden = YES;
                     fromView.transform = CGAffineTransformIdentity;
                     [UIView animateWithDuration:0.4
                                      animations:^{
                                        toView.transform = CGAffineTransformMake(1, 0, 0, 1, 0, 0);
                                      }
                                      completion:nil];
                   }];

Upvotes: 1

Views: 1744

Answers (1)

rakeshbs
rakeshbs

Reputation: 24572

I don't think the scale can be animated to 0 value because of divide by zero issues in the transformation matrix.

Check out in this link. http://www.wenda.io/questions/217747/uiview-scale-to-0-using-cgaffinetransformmakescale.html

And this CGAffineTransformMakeScale animation not working

You can instead use a small value to scale to and then hide the view after that like below

[UIView animateWithDuration:0.4
                     animations:^{
                         fromView.transform = CGAffineTransformMakeScale(0.01, 1);
                     }
                     completion:^(BOOL finished) {
                         fromView.hidden = YES;
                         fromView.transform = CGAffineTransformIdentity;
                         [UIView animateWithDuration:0.4
                                          animations:^{
                                              toView.transform = CGAffineTransformMakeScale(1, 1);
                                          }
                                          completion:nil];
                     }];

Upvotes: 3

Related Questions