UIKeyboardDidShowNotification called multiple times, and sometimes with incorrect keyboard dimensions

前端 未结 4 761
醉话见心
醉话见心 2021-02-07 08:12

I am trying to move a UITextView above the keyboard whenever the keyboard appears/changes. Let\'s say I have the English keyboard displaying and then switch directly to the Chin

4条回答
  •  深忆病人
    2021-02-07 08:48

    - (void)keyboardDidAppear:(NSNotification *)note {
        CGSize keyboardSize = [note.userInfo[UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
        UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
        textView.contentInset = contentInsets;
        textView.scrollIndicatorInsets = contentInsets;
    }
    
    - (void)keyboardWillBeHidden:(NSNotification *)note {
        UIEdgeInsets contentInsets = UIEdgeInsetsZero;
        textView.contentInset = contentInsets;
        textView.scrollIndicatorInsets = contentInsets;
    }
    

    The solution is from Apple's official solution here like 曹 said.

提交回复
热议问题