UIView animateWithDuration跳转到没有动画的最终变换

时间:2015-01-28 05:08:30

标签: ios uiview uiviewanimation

我有以下代码来创建翻转过渡。 fromView不会对变换设置动画并跳转到最终值,但toView会正确设置变换动画。这可能有什么问题?

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

1 个答案:

答案 0 :(得分:3)

由于转换矩阵中除以零问题,我不认为比例可以设置为0值。

查看此链接。 http://www.wenda.io/questions/217747/uiview-scale-to-0-using-cgaffinetransformmakescale.html

这是CGAffineTransformMakeScale animation not working

您可以改为使用较小的值进行缩放,然后隐藏视图,如下所示

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