尝试以下链接中的答案,layoutIfNeeded
应该在之前调用contentSize
。
iOS7 UITextView contentsize.height 替代
答案:
在 iOS7 中,UITextView
用于NSLayoutManager
布局文本:
// If YES, then the layout manager may perform glyph generation and layout for a given portion of the text, without having glyphs or layout for preceding portions. The default is NO. Turning this setting on will significantly alter which portions of the text will have glyph generation or layout performed when a given generation-causing method is invoked. It also gives significant performance benefits, especially for large documents.
@property(NS_NONATOMIC_IOSONLY) BOOL allowsNonContiguousLayout;
禁用allowsNonContiguousLayout
修复contentSize
:
textView.layoutManager.allowsNonContiguousLayout = NO;