zoukankan      html  css  js  c++  java
  • iOS7 UITextView 光标问题

    最近在项目中遇到UITextView在ios7上出现编辑进入最后一行时光标消失,看不到最后一行,变成盲打,stackOverFlow网站上有大神指出,是ios7本身bug,加上下面一段代码即可:

     1 -(void)textViewDidChange:(UITextView *)textView {
     2     CGRect line = [textView caretRectForPosition:
     3                    textView.selectedTextRange.start];
     4     CGFloat overflow = line.origin.y + line.size.height
     5     - ( textView.contentOffset.y + textView.bounds.size.height
     6        - textView.contentInset.bottom - textView.contentInset.top );
     7     if ( overflow > 0 ) {
     8         // We are at the bottom of the visible text and introduced a line feed, scroll down (iOS 7 does not do it)
     9         // Scroll caret to visible area
    10         CGPoint offset = textView.contentOffset;
    11         offset.y += overflow + 7; // leave 7 pixels margin
    12         // Cannot animate with setContentOffset:animated: or caret will not appear
    13         [UIView animateWithDuration:.2 animations:^{
    14             [textView setContentOffset:offset];
    15         }];
    16     }
    17 }

      

  • 相关阅读:
    Spring (4)框架
    Spring (3)框架
    Spring (2)框架
    javaSE面试题总结 java面试题总结
    分层结构
    三次握手
    17_网络编程
    16_多线程
    Ecplise中指定tomcat里Web项目发布文件
    Web 项目没有发布到我们安装的tomcat目录下
  • 原文地址:https://www.cnblogs.com/smallstong/p/4168064.html
Copyright © 2011-2022 走看看