iphone - 在 iOS 上,更改 UIView 对象的框架和中心可以改变其内部坐标系吗?

标签 iphone ios uiview frame bounds

在 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)。是否也可以通过仅更改 framecenter 而不是 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 坐标系中的位置。您无法通过 framecenter 属性实现该行为;它们只影响 View 在其父 View 坐标系中的位置。

关于iphone - 在 iOS 上,更改 UIView 对象的框架和中心可以改变其内部坐标系吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10728408/

相关文章:

iphone - iOS 自定义 URL 方案 - 获取源 URL

ios - 如何将按钮移动到随机位置?

ios - EXC_BAD_ACCES 绘图阴影

ios - 如何在透视中绘制图像?

ios - 从设备中删除应用程序不会清除 NSUserDefaults

iphone - UIWindow subview 在应用程序变为事件状态后消失

ios - 如何去掉 Swift 中导航后退按钮旁边的文本?

iphone - 学习 iOS 开发的核​​心数据

ios - 包含 TableView 的容器 View 根据输入数量 Swift 更改行数

ios - iPad - UIPageViewController - "dequeueReusableCellWithIdentifier"种选项