【问题标题】:Autolayout constraints boundary condition自动布局约束边界条件
【发布时间】:2019-10-07 23:38:39
【问题描述】:

我希望 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 的位置。我错过了什么吗?

【问题讨论】:

  • 附注:您提出了很多问题,但很少接受答案...您在这里没有得到太多帮助吗?

标签: ios autolayout uikit ios-autolayout


【解决方案1】:

这表示“扩展或收缩 view1,使其右边缘位于 view2 的左边缘”:

view1.rightAnchor.constraint(equalTo: view2.leftAnchor).isActive = true

添加这个:

view2.leftAnchor.constraint(greaterThanOrEqualTo: view1.leftAnchor).isActive = true

上面写着:“不要让 view2 的左边缘越过 view1 的左边缘”

【讨论】:

    猜你喜欢
    • 2019-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    相关资源
    最近更新 更多