我目前正在将非英语(希伯来语)富文本文件加载到 UITextView 中,如下所示。
self.textView.attributedText =
[NSAttributedString.alloc
initWithFileURL:[ NSBundle.mainBundle URLForResource:@"TextFile" withExtension:@"rtf" ]
options:nil
documentAttributes:nil
error:NULL
];
一切都正确加载,文件滚动,只是在下降过程中变得非常不稳定。我认为这是 UITextView 的渲染问题。
是否有其他库或方法可以使滚动平滑。 注意:UITextView 已经不可编辑且不可选择。
这可能并不理想,但我已经在类似的情况下实现了这个想法。尝试增加
UITextView
的高度(以创建某种缓冲区)。您可能需要调整各种 scrollIndicatorInsets
的 contentInsets
、layer.zPosition
、UIView
,并可能使 UITextView
透明,其后面有另一个 UITextView
,并具有适当的大小/边框/等,具体取决于你的布局。
选项2
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(40, 100, 200, 100)];
scrollView.scrollEnabled = YES;
scrollView.contentInset = UIEdgeInsetsZero;
[self.view addSubview:scrollView];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, scrollView.bounds.size.width, HEIGHT)];
label.text = @"text";
label.numberOfLines = 0;
[scrollView addSubview:label];
scrollView.contentSize = CGSizeMake(label.bounds.size.width, label.bounds.size.height);
我遇到了同样的问题,并且我找到了一种预加载文本的方法,这样即使在第一次滚动时它也不会滞后。
目标-C:
self.textView.attributedText = attributedText;
[self.textView.layoutManager ensureLayoutForCharacterRange:NSMakeRange(0, self.textView.attributedText.length)];
斯威夫特:
self.textView.attributedText = attributedText
self.textView.layoutManager.ensureLayout(forCharacterRange: NSRange(location: 0, length: self.textView.attributedText.length))