Scroll to bottom of UITextView erratic in iOS 7

前端 未结 9 1676
无人及你
无人及你 2020-12-01 04:58

The following code will work fine in iOS < 7.0. In iOS 7 the scrolling will be choppy and erratic while the UITextView is updating. I\'m not sure if this is a bug in iO

9条回答
  •  既然无缘
    2020-12-01 05:07

    There are two problems in iOS 7 that could explain your problem:

    • The contentOffset is not always up to date in iOS 7.
    • scrollRangeToVisible: will not scroll to an empty line at the end of the text view.

    The solution could be:

    -(void)scrollOutputToBottom {
        CGRect caretRect = [textView caretRectForPosition:textView.endOfDocument];
        [textView scrollRectToVisible:caretRect animated:NO];
    }
    

提交回复
热议问题