iOS7UITextView光标问题

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

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

1-(void)textViewDidChange:(UITextView *)textView {2CGRect line =[textView caretRectForPosition:3textView.selectedTextRange.start];4CGFloat overflow = line.origin.y +line.size.height5- ( textView.contentOffset.y +textView.bounds.size.height6- textView.contentInset.bottom -textView.contentInset.top );7if( 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 area10CGPoint offset =textView.contentOffset;11offset.y += overflow +7;//leave 7 pixels margin12//Cannot animate with setContentOffset:animated: or caret will not appear13[UIView animateWithDuration:.2animations:^{14[textView setContentOffset:offset];15}];16}17}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航