UIView的动画帧变化不平滑,导致弹性效果

Sou*_*Das 8 animation frame uiview ios

我试图动画UIView的帧变化,其中原点和大小都发生变化.动画看起来并不流畅,并且具有弹性效果.我使用以下代码来做到这一点

[UIView
    animateWithDuration:0.5
    animations:^{
        self.view.frame = newFrame;
    }];
Run Code Online (Sandbox Code Playgroud)

看起来大小首先变化非常快,然后原点随动画的指定持续时间而变化,最终导致弹性效果.如何让它看起来光滑?

Mel*_*son 12

您可以尝试更改动画曲线,也可以尝试线性曲线.

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    self.view.frame = newFrame;
    [UIView commitAnimations];
});
Run Code Online (Sandbox Code Playgroud)


Sou*_*Das 3

单独对每个子视图的帧变化进行动画处理就发挥了魔力。现在它的动画非常流畅。谢谢。