uitextview 最后一行遮挡

时间:2023-03-09 15:23:20
uitextview 最后一行遮挡

这只 uiscrollerview 的 setContentOffset

CGRect line = [textView caretRectForPosition:
textView.selectedTextRange.start];
CGFloat overflow = line.origin.y + line.size.height
- ( textView.contentOffset.y + textView.bounds.size.height
- textView.contentInset.bottom - textView.contentInset.top);
if ( overflow > ) {
// We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it)
// Scroll caret to visible area
CGPoint offset = textView.contentOffset;
offset.y += overflow + ; // leave 7 pixels margin
// Cannot animate with setContentOffset:animated: or caret will not appear
// [UIView animateWithDuration:.2 animations:^{
// [textView setContentOffset:offset];
// }];
[textView setContentOffset:offset];
}