Difference between Frame Rectangle and Alignment Rectangle

前端 未结 2 756
再見小時候
再見小時候 2020-12-23 12:49

Can anyone explain what is the difference between Frame Rectangle and Alignment Rectangle in the size inspector?

2条回答
  •  不知归路
    2020-12-23 13:30

    From Apple's old 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). enter image description here

    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.

    So, that pop-up menu in Xcode is providing you the ability to view and edit a view's size and position based on its alignment rect or its frame rectangle.

提交回复
热议问题