键盘覆盖Notes应用程序中的UITextView

嗨,我正在做一个笔记应用程序,我遇到了一个大问题。 我正在使用UITextView作为记事本。 当键盘出现时,它会阻止UITextView中的一些文本。 我在UITextView上有一个input附件视图。 我试图find在互联网上的答案,找不到一个很好的答案。任何方法来解决它? 这是一张图片:

您可能想要查看修改UITextView的contentOffset和contentInset。 毕竟,UITextField是一个UIScrollView的子类。

我决定用键盘高度减去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; 

您必须将contentInsetscrollIndicatorInsets设置为键盘高度的UIEdgeInsetscontentInset值使滚动高度更高,但允许您仍然在键盘下滚动内容。 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; }