CGAffineTransformMakeScale() distorting view frame

2019-07-21 10:08发布

I'm animating a view to make it appear as it is growing from the center of the screen with a theCGAffineTransformMakeScale(), it works fine in the iOS 8 beta 4 simulator but on the 7.1 version it distorts the frame of the view.

view.alpha     = 0.0f;
view.transform = CGAffineTransformMakeScale(0.95f, 0.95f);

[UIView animateWithDuration:0.5f
                      delay:0.0f
     usingSpringWithDamping:1.0f
      initialSpringVelocity:1
                    options:0
                 animations:^{
                    view.alpha     = 1.0f;
                    view.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
                             }
                 completion:nil];

And it worked well in the last beta in both the iOS 8 and iOS 7.1 versions. Anyone else having this problem, the view is a table of a UINavigationControl.

Doing some tests it seems the transform is stretching the views frame instead of scaling it during the animation.

Upon further testing i found out that only transforms that makes the view smaller(1.0 to 0.9 for example) cause it to change its width, if the transform makes the view bigger (1.1 to 1.0) and then animates it to its current normal scale, the animation performs without problems.

1条回答
2楼-- · 2019-07-21 10:36

You can sometimes get distortion when either the start or endpoint of the transformation has zero scale. Try setting your initial transform to something small but nonzero, e.g.

view.transform = CGAffineTransformMakeScale(0.01f, 0.01f);
查看更多
登录 后发表回答