0

大家好,我正在制作一个笔记应用程序,但遇到了一个大问题。我使用 UITextView 作为记事本。当键盘出现时,它会阻止 UITextView 中的一些文本。我在 UITextView 上有一个输入附件视图。我试图在互联网上找到答案,但找不到好的答案。有什么办法解决吗?这是一张图片:

4

3 回答 3

1

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

于 2013-07-07T16:56:34.737 回答
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;
于 2013-08-01T21:40:26.207 回答
1

您必须设置contentInsetscrollIndicatorInsetsUIEdgeInsets键盘高度。该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;
}
于 2013-08-07T14:55:06.700 回答