大家好我正在制作笔记应用程序而且遇到了一个大问题。我使用UITextView作为记事本。当键盘出现时,它会阻止UITextView中的一些文本。我在UITextView上有一个输入附件视图。我试图在互联网上找到答案,找不到一个好的答案。任何方法来解决它?这是一张图片:
答案 0 :(得分:1)
您可能希望查看修改UITextView的contentOffset和contentInset。毕竟,UITextField是一个UIScrollView子类。
答案 1 :(得分:1)
我决定用键盘高度减去UITextView高度:
NSDictionary* info = [notification userInfo];
kbSIZE = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
CGRect newTextViewFrame = self.notesTextView.frame;
newTextViewFrame.size.height -= kbSIZE.size.height;
newTextViewFrame.size.height += self.notesTextView.inputAccessoryView.frame.size.height;
self.notesTextView.frame = newTextViewFrame;
答案 2 :(得分:1)
您必须将contentInset
和scrollIndicatorInsets
设置为键盘高度的UIEdgeInsets
。 contentInset
值使滚动高度更高,但允许您仍然在键盘下滚动内容。 scrollIndicatorInsets
使滚动指示器停在键盘底部。
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *info = [notification userInfo];
CGSize kbSize = [info[UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
self.textView.contentInset = contentInsets;
self.textView.scrollIndicatorInsets = contentInsets;
}
- (void)keyboardWillHide:(NSNotification *)aNotification
{
self.textView.contentInset = UIEdgeInsetsZero;
self.textView.scrollIndicatorInsets = UIEdgeInsetsZero;
}