An article written by a foreign author introduces us to a new attribute in a iOS8,
var layoutmargins:uiedgeinsets
After we set the azimuth relationship between each uiview by holding down the Control key in IB (Interface Builder), click on the Position relationship property and you may see this relative to margin in the Properties panel.
Generally by default, this relative to margin is checked by default, if you do not want the system to check this option by default, please hold down the control and ALT key while dragging, then we can also set the Layoutmargins property to adjust the value, The default values are:
Uiedgeinsets (Top:8, Left:8, Bottom:8, Right:8)
Set the code:
Let Version = (Uidevice.currentdevice (). Systemversion as NSString). Doublevalueif version >= 8 {myview.layoutmargins = Uiedgeinsets ( top:0, left:40, bottom:0, right:0)}
There is also another attribute:
var Preservessuperviewlayoutmargins:bool
The article may look not very clear, I also read two times to see understand, preserves the basic meaning of this word is to protect, keep, again according to the article explanation, can so understand:
1. First understand the hierarchical relationship, the red view contains a brown view, the brown view contains a purple view.
2. The left value of the Red View Layoutmargins property is 40, but the brown view is on the leftmost side of the red view because relative to margin is not turned on in their leading position relationship.
3. Brown view the left value of the Layoutmargins property is 2, and the leading position constraint between the purple view and the brown view is relative to margin, so you can see that the purple view is offset by two pixels.
4. Brown View Preservessuperviewlayoutmargins:
4.1 Not open the case, the respective maintenance of their respective relations, non-interference, no impact.
4.2 On the case, the equivalent of the Brown view passes the margin value of the red view to the purple view, and the two values are the overlapping relationships, the margin value of the purple view relative to the left side of the brown view should be 40+2.
In addition, when the various attribute values of layoutmargins change, there are methods to notify:
Override Func Layoutmarginsdidchange () { println ("Layoutmarginsdidchange")}
This is basically the case with the code in Xcode layoutmargins Project.
3Q for Read It. ^_^
IOS8 Layout Margins