我在 stackoverflow 上阅读了所有存在的类似问题的解决方案,但并不缺乏。
当我尝试滚动文本以使用动画定位时,UITextView 出现问题。 当使用动画滚动时,文本的顶部会消失,但如果字体大小为 15pt,则一切正常,但如果大约 50pt,则出现问题。
您可以在视频中看到它 https://www.youtube.com/watch?v=EvIur672Q5k
我也尝试创建我自己的方法来使用循环动画滚动,每个循环移动 0.5pt 的偏移量它可以工作,但是这过多地使用了处理器,而且我无法控制动画时间,因为处理器过载。 https://www.youtube.com/watch?v=Kw5hx3YAdMw
我也尝试以相同的结果以编程方式创建 UITextView。
我尝试在具有线性曲线的部分上拆分动画,但它的抖动动画太丑了。
- (IBAction) start{
_textView.scrollEnabled = NO;
_textView.scrollEnabled = YES;
UITextPosition *Pos2 = [_textView positionFromPosition: _textView.beginningOfDocument offset: 501];
UITextPosition *Pos1 = [_textView positionFromPosition: _textView.beginningOfDocument offset: 500];
UITextRange *range = [_textView textRangeFromPosition:Pos1 toPosition:Pos2];
CGRect result1 = [_textView firstRectForRange:(UITextRange *)range];
result1.origin.x=0;
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
_textView.contentOffset = result1.origin;
} completion:^(BOOL finished){
}];
}
最佳答案
我相信你正在尝试这样做
- (IBAction)start:(id)sender {
_textView.scrollEnabled = NO;
_textView.scrollEnabled = YES;
NSRange bottom = NSMakeRange(_textView.text.length, 0);
[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
[_textView scrollRangeToVisible:bottom];
} completion:nil];
}
这应该为文本长度设置一个范围并滚动到它的底部。如果我误解了您的问题,请告诉我,我会尽力提供帮助
关于ios - 使用动画设置 setContentOffset 时,UITextView 大字体文本消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43151514/