textview防抖动 最后一行消失

来源:互联网 发布:peterson算法 编辑:程序博客网 时间:2024/06/05 17:41


// 防抖动

    CGRect line = [textViewcaretRectForPosition:

                   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 +0; // leave 7 pixels margin

        // Cannot animate with setContentOffset:animated: or caret will not appear

//        [UIView animateWithDuration:.1 animations:^{

            [textView setContentOffset:offset];

//        }];

    }

0 0
原创粉丝点击