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.


  • 相关阅读:
    延迟为程序集签名
    bootshrap会改变IE浏览器滚动条样式
    Spark算子选择策略
    kafka常用系统命令-1
    数据结构-树
    1.PyCharm 用法
    sql 语句用法
    linux命令
    linux命令
    es的相关知识二(检索文档)
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/5090115.html
Copyright © 2011-2022 走看看