【问题标题】:Keyboard covering UITextView in Notes App在 Notes 应用程序中覆盖 UITextView 的键盘
【发布时间】:2013-07-05 00:32:24
【问题描述】:

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

【问题讨论】:

标签: iphone ios uitextfield


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

    【解决方案3】:

    您必须将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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 1970-01-01
      • 2020-10-05
      • 2016-10-31
      • 2011-06-09
      • 1970-01-01
      相关资源
      最近更新 更多