码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-03-20 21:29:39      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

约束添加到父视图上

意思就是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 constraints 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 也就是整个的层级关系组合完成之后使用

  在viewDidLoad(:_)方法中写的时候会出错 

  在viewDidAppear(:_)方法正常使用

 

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

标签:

原文地址:http://www.cnblogs.com/baaingSheep/p/5299533.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!