在 iOS 上,如果我们更改 View 的 frame
,我们就会更改它的 bounds
,如果我们更改它的 bounds
,我们就会更改它的 框架
。
但是我们可以通过以下方式更改 View 的内部坐标系:
CGRect b = v.bounds; // v is the UIView object
b.origin.x = 10000;
b.origin.y = 10000;
v.bounds = b;
现在, View 的左上角坐标为(10000, 10000)
。是否也可以通过仅更改 frame
和 center
而不是 bounds
来实现?
最佳答案
On iOS, if we change a view's frame, we change its bounds, and if we change its bounds, we change its frame.
这句话只对了一半。只有这两个矩形的大小绑定(bind)在一起。来自文档:
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.
这并没有提到起源。因此,您的示例将修改内部坐标系的原点,而不更改其在 super View 坐标系中的位置。您无法通过 frame
或 center
属性实现该行为;它们只影响 View 在其父 View 坐标系中的位置。
关于iphone - 在 iOS 上,更改 UIView 对象的框架和中心可以改变其内部坐标系吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10728408/