[AutoLayout] 代码添加父视图的比例大小高度

约束添加到父视图上

意思就是imageView的高度等于self.view的height的0.5倍+0

        self.view.addConstraint(NSLayoutConstraint(item: imageView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0.5, constant: 0))

 

注意:

  

When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView(UIConstraintBasedLayout) 

 

  这个方法在hierarchy 也就是整个的层级关系组合完成之后使用

  也就是adSubview()之后 

  还有就是约束要完整 上一级的view 和自身的都是

  

posted @ 2016-03-20 20:40  baaingSheep  阅读(449)  评论(0编辑  收藏  举报