框架矩形和对齐矩形的区别

Difference between Frame Rectangle and Alignment Rectangle

谁能解释一下尺寸检查器[=20]中框架矩形对齐矩形的区别=]?

框架描述了在屏幕上放置视图的位置以及这些视图的大小。布置视图时,约束使用称为对齐矩形的相关几何元素。

对齐矩形基于项目内容的呈现,自动布局使用对齐矩形而不是项目的框架矩形。 通过使用对齐矩形而不是框架,自动布局确保在布局过程中正确考虑视图的边缘和中心等关键信息。 与框架不同,视图的对齐矩形应限于核心视觉元素。当新项目被绘制到视图上时,它的大小应该不受影响。

考虑图-1 的左侧。它显示了一个用阴影和徽章绘制的视图。布置此视图时,您希望自动布局只专注于对齐核心元素(蓝色矩形)而不是装饰。

图-1:视图的对齐矩形(居中)严格指要对齐的核心视觉元素,没有修饰。

图-1 中的中心图像突出显示了视图的对齐矩形。这个矩形排除了所有装饰,例如阴影和徽章。这是您希望自动布局在其工作时考虑的视图的一部分。 图 -1 中的 right-hand 矩形包含视图的所有可视元素。它包含阴影和徽章。如果在布局期间考虑这些装饰品,它们可能会影响视图的对齐功能(如居中、底部和右侧)。

图 -2 自动布局在其父视图中居中布局时仅考虑此视图的对齐矩形。阴影和徽章不影响其位置。

参考:link

来自 Apple 的旧 Auto Layout Guide:

Layout Operates on Alignment Rectangles, Not on Frames

When considering layout, keep in mind that the frame of a control is less important than its visual extent. As a result, ornaments such as shadows and engraving lines should typically be ignored for the purposes of layout. Interface Builder ignores them when positioning views on the canvas—in the following example, the Aqua guide (the dashed blue line) aligns with the visual extent of the button, not with the button’s frame (the solid blue rectangle).

To allow layout based on the presentation of the content rather than the frame, views provide an alignment rectangle, which is what the layout actually operates on. To determine whether your override is correct on OS X, you can set the NSViewShowAlignmentRects default to YES to draw the alignment rects.

因此,Xcode 中的 pop-up 菜单使您能够根据视图的对齐矩形或框架矩形查看和编辑视图的大小和位置。