我做了一個示例演示,當我在UITextview
上鍵入時,它將展開,但視圖不會展開,這是UITextview
的超級視圖。如何使用UITextview增加視圖大小?
代碼
- (void)textViewDidChange:(UITextView *)textView
{
CGFloat fixedWidth = textView.frame.size.width;
CGSize newSize = [textView sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
textView.frame = newFrame;
self.myTextView.scrollEnabled = NO;
CGRect viewFrame = self.myCommentView.frame;
viewFrame.size.height =self.myCommentView.frame.size.height + 1;
viewFrame.origin.y=self.myCommentView.frame.origin.y - 1;
self.myCommentView.frame =viewFrame;
[self.myTextView layoutIfNeeded];
[self.myCommentView layoutIfNeeded];
}
問題是
觀點不符合UITextview
擴大。而如果視圖中展開UITextview
並沒有擴張。
將高度約束關係從'='更改爲'> ='。 –
不工作,給我錯誤 – user7018875
約束不正確。 –