UITextView in iOS7 doesn't scroll

摘要:
UITextViewiniOS7真的很奇怪。键入并重新输入UITextView的弹性线时,滚动视图不会像应有的那样滚动到底部,并会导致文本被“剪切”。问题在于OS7
UITextView in iOS7 has been really weird. As you type and are entering the last line of your UITextView, the scroll view doesn't scroll to the bottom like it should and it causes the text to be "clipped".

The problem is due to iOS 7. In the text view delegate, add this code:
- (void)textViewDidChange:(UITextView *)textView {
    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 > 0 ) {
        // 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 + 7; // leave 7 pixels margin
        // Cannot animate with setContentOffset:animated: or caret will not appear
        [UIView animateWithDuration:.2 animations:^{
            [textView setContentOffset:offset];
        }];
    }
}


It worked.


免责声明:文章转载自《UITextView in iOS7 doesn't scroll》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Gedit中文乱码spring mvc实现新增用户下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

UITextView 和 UITextField限制字符数和表情符号

UITextField限制字符数 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ int pMaxLength = 12; NSInteg...

Swift UITextView设置富文本点击, 取消一切点击事件(放大镜/复制粘贴/删除等等)

1. 设置富文本,超链接点击 2. 取消一切点击事件(放大镜/复制粘贴/删除等等) /// 同意协议view class TGSLoginAgreeView: UIView, UITextViewDelegate { ///点击类型 enum ClickLinkType { ///用户协议 cas...

iOS UI-文本视图(UITextView)

1 #import "ViewController.h" 2 3 @interface ViewController ()<UITextViewDelegate> 4 5 @property (strong, nonatomic) UITextView *textView; 6 7 @end 8 9 @implement...