如何以编程方式更改文本域的约束?

时间:2018-03-23 09:29:34

标签: ios swift nslayoutconstraint

我有菜单图标和文本字段。当调用textFieldDidBeginEditing方法时,我想隐藏菜单图标并将文本字段的位置更改为安全区域顶部。我已将textfield的顶部与菜单图标相关联。所以我需要以编程方式添加常量和安全区域。 谢谢。

1 个答案:

答案 0 :(得分:1)

取出菜单图标heightConstraint的出口并将其设置为零。在textview endediting上将其设置为default位置。

工作原理:

在textView开始编辑之前

textView.top(w.r.t safearea) = textView.top(w.r.t menu button) + btnmenu.height + btnMenu.top (w.r.t safearea)

textView开始编辑为btnmenu.height = 0

textView.top(w.r.t safearea) = textView.top(w.r.t menu button) +  btnMenu.top (w.r.t safearea)

Diametric说明:

  • 左:在textView开始编辑之前

  • 右:textView开始编辑为btnmenu.height = 0

enter image description here

注意:您可以选择BtnMenu.top&的限制条件。 BtnMenu.bottom并根据您的需要设置它们。

希望现在你会被清除。

相关问题