问题描述
上面那个黄色框是一个可编辑的 UITextView,当前正在编辑(是第一响应者).但你可能分不清吧?因为没有游标.但是有……就是黄色textView左下角的那个小蓝点.它略低于 textViews 底部边框.因此,如果我继续换行或按回车键,文本将自然向上移动.但是光标永远不会是水平"的,或者是在 UITextView 的底部边框上方.它总是勉强从底部伸出,在边界下方几个点.
That yellow box above is an editable UITextView that is currently being edited (is first responder). But you probably couldn't tell right? Because there is no cursor. But there is... It's that small blue dot in the bottom left of the yellow textView. It's slightly below the textViews bottom border. So if I keep going to a new line, or pressing enter, the text will move up as it naturally should. But the cursor is never "level", or right above the UITextView's bottom border. It's always just barely poking out of the bottom, a couple points below the border.
为什么?这在 iOS 6 中不是问题.有什么方法可以解决这个问题?
Why? This wasn't a problem in iOS 6. Any way to fix this?
推荐答案
这个bug在iOS 7.0,你可以通过修改textView的委托方法来解决.
this bug is in iOS 7.0 you can solve this by modifying textView delegate method.
试试下面的代码
- (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];
}];
}
}
你的问题会解决的.
这篇关于在 iOS 7 中编辑时 UITextView 光标无法正确定位.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)