使用NSLayoutAnchor时明确的约束
问题描述:
我是新创建视图,没有界面构建器。 我使用NSLayoutAnchors
来创建视图!使用NSLayoutAnchor时明确的约束
当我使用的视图 - 控制创造了这样一些观点:
let borderView:UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor.lightGray
view.isUserInteractionEnabled = false
view.alpha = 0.5
return view
}()
然后我用这个观点来边境某事鉴于这样的:
view.addSubview(borderView)
borderView.bottomAnchor.constraint(equalTo: headerView.bottomAnchor).isActive = true
borderView.leftAnchor.constraint(equalTo: headerView.leftAnchor).isActive = true
borderView.rightAnchor.constraint(equalTo: headerView.rightAnchor).isActive = true
borderView.heightAnchor.constraint(equalToConstant: 1).isActive = true
另一种观点认为我
然后试试这个:
informationView.addSubview(borderView)
borderView.topAnchor.constraint(equalTo: informationView.topAnchor).isActive = true
borderView.leftAnchor.constraint(equalTo: informationView.leftAnchor).isActive = true
borderView.rightAnchor.constraint(equalTo: informationView.rightAnchor).isActive = true
borderView.heightAnchor.constraint(equalToConstant: 1).isActive = true
,但看起来这种观点有它的前一个约束高端展会约束错误!
如何在重用之前删除borderView
约束条件?
的可能的复制[删除影响一个UIView所有约束(http://stackoverflow.com/questions/24418884/remove-all-constraints -affecting-a-uiview) – dirtydanee
这不是重复的,因为答案不是重用视图(在这种情况下删除约束不会有帮助) –