Xcode6 Constrain to margins

来源:互联网 发布:沪港通资金流向 软件 编辑:程序博客网 时间:2024/05/18 11:45

Xcode6多了个内边距, Constrain to margins 

在stack overflow上边看到了一个帖子:楼主的约束莫名多了16像素空隙。

一下是一些回复:

In iOS 8 you now have the option to define your constrains relative to a predefined margin to the superview's bounds, instead of the superview's bounds themselves. Yes, it is totally related to the layout margins you pointed to in the docs. One advantage is that you may redefine your margins dynamically, or differently for each kind of device, and the layout will be updated correspondingly without modifying the constraints.When to use it: when you want to take advantage of this new flexibility.When to NOT use it: for any app targeted to run on iOS 7 or below.

这个是从官方文档上考下来的,意思是说iOS8默认多了个margin,你可以通过设置margin来控制默认的缝隙。


另一个回复直接给出了属性:

The property on UIView is: layoutMargins. See the Apple Docs. Basically if the layout margins are 8,8,8,8 (the default), a constraint with 0 leading space to container margin will have an x position of 8. Note that this is only available on iOS8 or later.For everyone who doesn't want their constraints to go to the container margin:CTRL+click+drag to show the constraint creation popup.If the menu shows to create the constraint to the margin by default, hold down option/alt to allow the constraint to be made to the container and not the container margin.Now it will show the option to create the constraint NOT to the margin. This is WAY faster in my usage.

iOS8在UIView中添加了新的属性:

/* -layoutMargins returns a set of insets from the edge of the view's bounds that denote a default spacing for laying out content. If preservesSuperviewLayoutMargins is YES, margins cascade down the view tree, adjusting for geometry offsets, so that setting the left value of layoutMargins on a superview will affect the left value of layoutMargins for subviews positioned close to the left edge of their superview's bounds If your view subclass uses layoutMargins in its layout or drawing, override -layoutMarginsDidChange in order to refresh your view if the margins change. */@property (nonatomic) UIEdgeInsets layoutMargins NS_AVAILABLE_IOS(8_0);@property (nonatomic) BOOL preservesSuperviewLayoutMargins NS_AVAILABLE_IOS(8_0); // default is NO - set to enable pass-through or cascading behavior of margins from this view’s parent to its children- (void)layoutMarginsDidChange NS_AVAILABLE_IOS(8_0);


对于我这刚学autolayout的,我习惯还是不勾选这个框,因为发帖子的作者碰到了storyboard在Xcode5上打不开。不过建议还是默认勾选,这样设置调整起来相当方便。



0 0
原创粉丝点击