[英]Updating Main.storyboard constraints programatically (Swift)
我想將 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 為零...似乎以編程方式我無法訪問我在故事板中設置的內容。 任何想法為什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.