UIView 的框架原点与其中心之间的关系是什么?

What is the relationship between a UIView's frame origin and its center?

假设我正在创建一个动画,我想将 UIView 的中心移动到某个 CGPoint 我有。我知道我想要的中心是什么,就是前面提到的 CGPoint,我知道我想要的宽度和高度,但是当我去为我的 UIView 创建框架时,我不知道是什么为 xy 设置为 origin

我应该只设置 0, 0 还是什么?重要吗?

我是否应该考虑将 center 设置为另一种设置原点的方法?让我希望 CGRect 有一个带有 center 作为选项的实例化器。

之前有一个问题解决了一个有点类似的问题,但它将它们作为三个独立的实体来解决,而不是在创建视图时如何处理中心。

是的,继续将初始框架的原点设置为任何值,因为随后设置中心将有效地移动该原点。当稍后要完全配置时,使用 CGRectZero 框架初始化视图并不少见。

frame 实际上只是根据视图的 centerbounds 计算出的 属性,因此在视图布局方面,这三者有着内在的联系。 UIView Class Reference 是这样说的:

The geometry of a view is defined by its frame, bounds, and center properties. The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view. The center property can be used to adjust the position of the view without changing its size. The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both.