自动布局约束边界条件
Autolayout constraints boundary condition
我希望 view1 的右约束等于 view2 的左约束,但如果 view2 移过 view1 的左侧(边界条件)则不是。这是我的限制条件:
view1.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0).isActive = true
view1.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
view1.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
view1.leftAnchor.constraint(greaterThanOrEqualToSystemSpacingAfter: contentView.leftAnchor, multiplier: 1.0).isActive = true
let rightBoundaryConstraint = view1.rightAnchor.constraint(equalTo: iew2.leftAnchor)
rightBoundaryConstraint.priority = UILayoutPriority(999)
rightBoundaryConstraint.isActive = true
我怀疑这仍然不能 100% 确定 view1 的位置。我错过了什么吗?
这表示 "expand or contract view1 so its right-edge is at the left-edge of view2":
view1.rightAnchor.constraint(equalTo: view2.leftAnchor).isActive = true
添加这个:
view2.leftAnchor.constraint(greaterThanOrEqualTo: view1.leftAnchor).isActive = true
表示:"Don't let view2's left-edge go past view1's left edge"
我希望 view1 的右约束等于 view2 的左约束,但如果 view2 移过 view1 的左侧(边界条件)则不是。这是我的限制条件:
view1.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 0).isActive = true
view1.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true
view1.topAnchor.constraint(equalTo: contentView.topAnchor).isActive = true
view1.leftAnchor.constraint(greaterThanOrEqualToSystemSpacingAfter: contentView.leftAnchor, multiplier: 1.0).isActive = true
let rightBoundaryConstraint = view1.rightAnchor.constraint(equalTo: iew2.leftAnchor)
rightBoundaryConstraint.priority = UILayoutPriority(999)
rightBoundaryConstraint.isActive = true
我怀疑这仍然不能 100% 确定 view1 的位置。我错过了什么吗?
这表示 "expand or contract view1 so its right-edge is at the left-edge of view2":
view1.rightAnchor.constraint(equalTo: view2.leftAnchor).isActive = true
添加这个:
view2.leftAnchor.constraint(greaterThanOrEqualTo: view1.leftAnchor).isActive = true
表示:"Don't let view2's left-edge go past view1's left edge"