我的目标只是iOS7。
我想在显示键盘时'调整'UITextView
,以便可以看到所有文字,而不是隐藏在键盘后面。
我已经考虑了几种不同的方法......
1)键盘显示时更改UITextView
的框架。
以下问题详述了我使用此方法时遇到的同样问题 - 尽管正确设置了帧,但最后一行/游标将超出UITextView
的范围,因此不在视线范围内:< / p>
UITextView cursor below frame when changing frame
您可以从以下屏幕截图中看到此效果。 UITextView
具有绿色背景。它已添加到红色背景的UIView
。箭头显示光标所在的位置......
2)更改contentInset
UITextView
属性
我相信这种推荐/首选方法。请注意,我已阅读Apple文档,以根据出现/消失的键盘调整视图大小:
使用我的代码,当我更改UIEdgeInsets
的底部组件时,我没有任何效果。
与上面的示例相同,红色UITextView
上的绿色UIView
,文字在键盘下方消失:
这是代码:
- (void)keyboardWillShow:(NSNotification*)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets insets = _textView.contentInset;
insets.bottom += keyboardSize.height;
_textView.contentInset = insets;
_textView.scrollIndicatorInsets = insets;
}
注意:scrollIndicatorInsets
部分正常。用屏幕截图很难描绘,但滚动指示器在正确的位置开始和停止,并且看起来是正确的大小。
我已经阅读了一些人们遇到类似问题的问题。
3)更改textContainerInset
上的UITextView
此问题的答案建议在iOS 7上使用textContainerInset
代替contentInset
:
UITextView contentInset not working in UITextView on iOS 7?
我也尝试了这一点,但仍无法调整UITextView
的大小。
在这个问题中,“mann”也遇到了contentInset
和textContainerInset
的问题:
UITextView content Inset Bottom not working iOS7
问题
textContainerInset
还是contentInset
?contentInset
的代码中,我错过了什么?我还需要设置其他东西吗?由于
答案 0 :(得分:5)
这是iOS 7中的一个错误.Pete Stenberger用UITextView的子类解决了这个问题。你可以在这里找到它:
https://github.com/steipete/PSPDFTextView
以下是更多信息:
http://petersteinberger.com/blog/2014/fixing-uitextview-on-ios-7/