在 UITextView 中显示富文本文件导致 Choppy/Slow 滚动
Displaying Rich Text File in UITextView Causes Choppy/Slow Scrolling
我目前正在像这样将非英语(希伯来语)富文本文件加载到 UITextView 中。
self.textView.attributedText =
[NSAttributedString.alloc
initWithFileURL:[ NSBundle.mainBundle URLForResource:@"TextFile" withExtension:@"rtf" ]
options:nil
documentAttributes:nil
error:NULL
];
一切都正确加载并且文件滚动,只是在向下的过程中变得非常不稳定。我认为这是 UITextView 的渲染问题。
是否有任何其他库或方法可以使滚动流畅。
注意:UITextView 已经是不可编辑和不可选择的了。
这可能不太理想,但我曾在类似情况下使用过这个想法。尝试增加 UITextView
的高度(以创建一种缓冲区)。您可能需要调整各种 UIView
的 scrollIndicatorInsets
、contentInsets
、layer.zPosition
,并可能使 UITextView
与另一个 UITextView
透明根据您的布局,在其后面使用适当的 size/border/etc。
选项 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);
我目前正在像这样将非英语(希伯来语)富文本文件加载到 UITextView 中。
self.textView.attributedText =
[NSAttributedString.alloc
initWithFileURL:[ NSBundle.mainBundle URLForResource:@"TextFile" withExtension:@"rtf" ]
options:nil
documentAttributes:nil
error:NULL
];
一切都正确加载并且文件滚动,只是在向下的过程中变得非常不稳定。我认为这是 UITextView 的渲染问题。
是否有任何其他库或方法可以使滚动流畅。 注意:UITextView 已经是不可编辑和不可选择的了。
这可能不太理想,但我曾在类似情况下使用过这个想法。尝试增加 UITextView
的高度(以创建一种缓冲区)。您可能需要调整各种 UIView
的 scrollIndicatorInsets
、contentInsets
、layer.zPosition
,并可能使 UITextView
与另一个 UITextView
透明根据您的布局,在其后面使用适当的 size/border/etc。
选项 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);