我想在键盘出现时调整 UITextView 的大小,但我似乎无法做到这一点。我创建了一个带有 UITextView 的视图。在代码中,我想手动调整这个文本视图的高度。我这样做:
_textView.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *constraint = [NSLayoutConstraint constraintWithItem:_textView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:216.0f];
[_textView addConstraint:constraint];
在Interface Builder中,我说text view和superview之间的margin可以大于等于0。
当我运行该应用程序时,它给出了无法同时满足约束的错误:
"<NSLayoutConstraint:0x886e550 V:[UITextView:0x7b0fa00(216)]>",
"<NSLayoutConstraint:0x886f7c0 UITextView:0x7b0fa00.bottom == UIView:0x886e3c0.bottom>",
"<NSLayoutConstraint:0x886f700 V:|-(0)-[UITextView:0x7b0fa00] (Names: '|':UIView:0x886e3c0 )>",
"<NSAutoresizingMaskLayoutConstraint:0x71a2d10 h=--- v=--- V:[UIWindow:0x8a792f0(480)]>",
"<NSAutoresizingMaskLayoutConstraint:0x71a1490 h=-&- v=-&- UIView:0x886e3c0.height == UIWindow:0x8a792f0.height - 20>"
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x886e550 V:[UITextView:0x7b0fa00(216)]>
我不确定如何确保满足所有约束。谁能帮我解决这个问题?
谢谢!