NSLayout​Constraint

NSLayout​Constraint:定义了UI属性有参照关系的两个UI元素,一个元素的frame变化时,另一个元素变化的规则;依赖依附于最近的共同父视图,包含参照元素本身。

首要:确定变化参考物;参考物的尺寸发生变化,系统会自动重新计算。

/* Create constraints explicitly.  Constraints are of the form "view1.attr1 = view2.attr2 * multiplier + constant" 

 If your equation does not have a second view and attribute, use nil and NSLayoutAttributeNotAnAttribute.

 */

+(instancetype)constraintWithItem:(id)view1 attribute:(NSLayoutAttribute)attr1 relatedBy:(NSLayoutRelation)relation toItem:(nullable id)view2 attribute:(NSLayoutAttribute)attr2 multiplier:(CGFloat)multiplier constant:(CGFloat)c;

A constraint defines a relationship between two user interface objects that must be satisfied by the constraint-based layout system. Each constraint is a linear equation with the following format:

item1.attribute1 = multiplier × item2.attribute2 + constant

In this equation, attribute1 and attribute2 are the variables that Auto Layout can adjust when solving these constraints. The other values are defined when you create the constraint. For example, If you’re defining the relative position of two buttons, you might say “the leading edge of the second button should be 8 points after the trailing edge of the first button.” The linear equation for this relationship is shown below:

 
原文地址:https://www.cnblogs.com/feng9exe/p/6651381.html