【发布时间】:2016-09-28 17:13:26
【问题描述】:
我正在尝试将图像视图固定到超级视图的顶部、左侧和右侧,并使用 NSLayoutConstraint 给它一个高度,如下所示:
backgroundView.addSubview(imageView)
backgroundView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .Top, relatedBy: .Equal, toItem: backgroundView, attribute: .Top, multiplier: 1.0, constant: 0.0))
backgroundView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .Left, relatedBy: .Equal, toItem: backgroundView, attribute: .Left, multiplier: 1.0, constant: 0.0))
backgroundView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .Right, relatedBy: .Equal, toItem: backgroundView, attribute: .Right, multiplier: 1.0, constant: 0.0))
backgroundView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: view.bounds.width))
但是图像没有显示,并且调试器正在记录我的约束已被破坏。我看不出是什么限制导致了这个问题。
【问题讨论】:
标签: ios swift autolayout nslayoutconstraint