ios - 如何控制uitextview中自动滚动的速度

标签 ios uiscrollview nstimer

如何控制 UITextView 中滚动文本的速度。我是 iOS 的新手,无法弄清楚这一点。下面是我调用以启动滚动的方法。

[InputTextField scrollRangeToVisible:NSMakeRange([InputTextField.text length]-1, -1)];

我希望能够改变滚动的速度。 谢谢

最佳答案

你不能改变 scrollRangeToVisible 的动画速度,但你可以使用 contentOffset

确保你使用的是 UITextView,这不适用于 UITextField

   uint offset1=-1; 
   uint offset2=0;

    UITextPosition *Pos2 = [_textView positionFromPosition: _textView.endOfDocument offset: offset2];
    UITextPosition *Pos1 = [_textView positionFromPosition: _textView.endOfDocument offset: offset1];
    UITextRange *range = [_textView textRangeFromPosition:Pos1 toPosition:Pos2];

CGRect result1 = [_textView firstRectForRange:(UITextRange *)range];
result1.origin.x=0;//reset x position to zero



[UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationOptionCurveLinear
                      animations:^{

                     _textView.contentOffset = result1.origin;
}
completion:^(BOOL finished){                                                  
}];

关于ios - 如何控制uitextview中自动滚动的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9952188/

相关文章:

ios - CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION 移除了吗?

ios - 防止 UIScrollView 向上移动超过起始位置

ios - 如果新的被解雇,如何取消以前的 NSTimer

ios - 如何在最新的 Firebase IOS SDK 中获取 Firebase JWT token 以在服务器端进行验证

ios - swift - "Expected to decode Array<Any> but found a dictionary instead."

ios - UIScrollView 以启动为中心

ios - 创建一个从 xml 文件中提取所有数据的 ScrollView

ios - 如何实现超时/等待NSStream有效地使方法同步

ios - NSTimer 毫秒精度

ios 7.0 模拟器不会在 xcode 6.0.1 中下载