【发布时间】:2021-12-20 09:01:06
【问题描述】:
我想将我的 textview 的底部锚点更新为等于键盘高度的常量,这样它就不会覆盖 textView 中的文本。我在 Main.storyboard 中有一个约束标识符为我的 textView 设置为“bottomTextViewConstraint”,我们还有以下代码:
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
print("This prints")
for constraint in self.textView.constraints {
print("This does not print")
if constraint.identifier == "bottomTextViewConstraint" {
constraint.constant = keyboardSize.height
print("This does not print")
}
}
textView.updateConstraints()
}
}
}
self.textView.constraints 为零...似乎以编程方式我无法访问我在情节提要中设置的内容。任何想法为什么?
【问题讨论】:
标签: ios swift textview constraints xcode-storyboard