简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM