码迷,mamicode.com
首页 > 移动开发 > 详细

iOS7 UITextView 光标问题

时间:2014-12-23 10:19:26      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

最近在项目中遇到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 }

 

  

iOS7 UITextView 光标问题

标签:

原文地址:http://www.cnblogs.com/smallstong/p/4168064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!