zoukankan      html  css  js  c++  java
  • UITextView in iOS7 doesn't scroll

    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.


  • 相关阅读:
    Handler使用入门 下载文件
    基于QT前端的mplayer播放器2
    HTTP协议详解(真的很经典)
    安装 gentoo minimal cd
    linux 分区方案
    MFC 中添加按钮和事件
    makefile 学习
    堆和栈
    paste命令使用
    cut用法
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/5090115.html
Copyright © 2011-2022 走看看