我使用此代码尝试调整视图的大小,输出看起来也不错。但是,视图不会调整大小,并且仅对一行保持相同的高度...
if self.inputToolbar.contentView.textView.contentSize.height > self.inputToolbar.contentView.textView.frame.size.height {
print("content size : \(self.inputToolbar.contentView.textView.contentSize.height)")
print("frame size : \(self.inputToolbar.contentView.textView.frame.size.height)")
let fixedWidth = self.inputToolbar.contentView.textView.frame.size.width;
self.inputToolbar.contentView.textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude));
var newFrame = self.inputToolbar.contentView.textView.frame;
let newSize = self.inputToolbar.contentView.textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude));
print(newSize.height.description)
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height);
self.inputToolbar.contentView.textView.frame = newFrame;
print("content size : \(self.inputToolbar.contentView.textView.contentSize.height)")
print("frame size : \(self.inputToolbar.contentView.textView.frame.size.height)")
}
self.inputToolbar.contentView.textView.isScrollEnabled = false;//no matter this, w/ or w/o it does the same
输出:
content size : 49.0
frame size : 36.0
49.0
content size : 49.0
frame size : 49.0
您可以看到框架已调整大小,但文本输入未调整大小...我使用的是JQSMessenger