NSLayoutConstraint 设置优先级
Posted qingzz
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NSLayoutConstraint 设置优先级相关的知识,希望对你有一定的参考价值。
//显示提交按钮 时的约束 private var svBottomCon:NSLayoutConstraint? //隐藏提交按钮 时的约束 private var svUpdateBottomCon:NSLayoutConstraint? //显示有数据的UI , 不能编辑,隐藏提交按钮 此时设至 高约束等级 defaultHigh
func showDataUI(){ bindCardView.updateTempUI() self.submitBtn.isHidden = true if #available(ios 11.0, *) { svUpdateBottomCon = scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20) } else { svUpdateBottomCon = scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -20) } svUpdateBottomCon?.priority = UILayoutPriority.defaultHigh svUpdateBottomCon?.isActive = true }
//默认UI 设置 第一次的约束等级是defaultLow
if #available(iOS 11.0, *) { scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true svBottomCon = scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -102) submitBtn.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -30).isActive = true } else { scrollView.topAnchor.constraint(equalTo: view.topAnchor, constant: 20).isActive = true svBottomCon = scrollView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -102) submitBtn.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -30).isActive = true } svBottomCon?.priority = UILayoutPriority.defaultLow svBottomCon?.isActive = true
以上是关于NSLayoutConstraint 设置优先级的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Swift 中为 NSLayoutConstraint 设置动画?
NSLayoutConstraint - 无法将子视图框架设置为父视图边界