OGeek|极客世界-中国程序员成长平台

标题: ios - UIInterfaceOrientation、CGAffineTransform、框架、边界和中心 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:45
标题: ios - UIInterfaceOrientation、CGAffineTransform、框架、边界和中心

有人能指点我上面的一本很好的入门书吗?当你和其他人搞混时会发生什么?似乎无论我做什么,一旦我开始弄乱状态栏方向或 View 变换(即使我所做的只是 90 度旋转),我可以指望我的 View 最终会横向,向上上下颠倒,在一个令人沮丧的下午尝试和错误试图让它们理顺。我敢肯定,一旦您知道了逻辑以及应用所有内容的顺序,这一切都是有道理的,但是到目前为止,凭经验,我还无法弄清楚。



Best Answer-推荐答案


我不知道关于该主题的好的单文档入门,但以下是我从经验和阅读文档中学到的东西。

中心、边界和框架

如果您设置框架,则中心和边界将被更新。如果您设置中心或边界,则框架将被更新。 Frame 是一种使用 super View 的坐标系来操作中心和边界的便捷方法。

来自 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.

The Relationship of the Frame, Bounds, and Center Properties了解更多详情。

变换

如果您将变换属性设置为身份变换之外的其他内容,则框架未定义。如果您将变换设置为其他内容,您应该只使用中心(将 View 定位在其 super View 中)和边界(调整 View 的大小)来操作 View 几何图形。以下是来自 UIView Class Reference 的相关信息:

The origin of the transform is the value of the center property, or the layer’s anchorPoint property if it was changed. (Use the layer property to get the underlying Core Animation layer object.) The default value is CGAffineTransformIdentity.

...

Warning If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

Coordinate System Transforms了解更多详情。

UIInterfaceOrientation

UIInterfaceOrientation 不会直接影响变换、边界、中心或框架属性。但是,当设备方向发生变化时, View Controller 会自动调整其 subview 的大小(这会反过来调整其 subview 的大小等等)。

Responding to Device Orientation ChangesView Controller View Resizing了解更多详情。

关于ios - UIInterfaceOrientation、CGAffineTransform、框架、边界和中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4675870/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4