动画视图控制器视图的边界原点时实际发生了什么?

What actually happens when animating bounds origin of a view controller's view?

如果我为视图控制器视图的边界原点设置动画:

UIView.animate(withDuration: 1) {
    self.view.bounds.origin.y = 20
}

它的所有子视图都向上动画 20 点。但我想我只是将边界原点向下移动了 20 点,那么为什么子视图不向下移动 20 点呢?当我执行此动画时实际发生了什么?

还是简单的说在bounds坐标系中,正向就是向上?

我相信您可能将视图的 bounds 与视图的 frame 混淆了。

But I thought I just moved the bounds origin down 20 points, so why don't the subviews move downward by 20?

不,如果您将 frame(此视图位于其父视图的坐标系中)向下移动 20,那么它(及其子视图)将向下移动 20。但是您调整了 bounds,而不是 frame.

What is actually happening when I perform this animation?

为了使其更易于查看,我将为相关视图提供其自己的背景颜色,以便您可以看到与其子视图相关的视图。下面,我将边界移动了 50 个点。通过将 boundsorigin 从 0, 0 更改为 0, 50,我们表示“此视图自身坐标系的左上角不再是 0, 0,而是 0 , 50”, 从而将其所有子视图向上移动 50: