切换系统自带键盘为自定义键盘

  if (self.textView.inputView == nil) { // 切换为自定义的表情键盘

        HWEmotionKeyboard *emotionKeyboard = [[HWEmotionKeyboard alloc] init];// 自定义的键盘

        emotionKeyboard.width = self.view.width;

        emotionKeyboard.height = 216;

        self.textView.inputView = emotionKeyboard;

    } else { // 切换为系统自带的键盘

        self.textView.inputView = nil;

    }

     // 开始切换键盘

    self.switchingKeybaord = YES;//申明一个BOOL值监听键盘的切换

    // 退出键盘

    [self.textView endEditing:YES];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

        [self.textView becomeFirstResponder];

        self.switchingKeybaord = NO;// 结束键盘

    });

#pragma mark - 监听方法

/**

 * 键盘的frame发生改变时调用(显示、隐藏等)

 */

- (void)keyboardWillChangeFrame:(NSNotification *)notification

{

    // 如果正在切换键盘,就不要执行后面的代码

    if (self.switchingKeybaord) return;

}

原文地址:https://www.cnblogs.com/happyEveryData/p/5516660.html