首页 > 代码库 > 新浪微博客户端(41)-切换表情键盘

新浪微博客户端(41)-切换表情键盘

 

DJComposeViewController.m

#pragma mark - 切换键盘
- (void)switchKeyboard {
    
    // textView.inputView 代表的就是键盘
    if (self.textView.inputView) { // 默认self.textView.inputView = nil, 为nil则代表默认为系统键盘
        self.textView.inputView = nil;
    } else {
        DJEmotionKeyboard *emotionKeyboard = [[DJEmotionKeyboard alloc] init];
        emotionKeyboard.width = self.view.width;
        emotionKeyboard.height = 216; // IOS 系统键盘高度一般都是216
        self.textView.inputView = emotionKeyboard;
    }
 
    // 先调用endEditing,再调用becomeFirstResponder才可造成键盘效果
    [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];
    });
    
}

最终效果:

技术分享 

 

新浪微博客户端(41)-切换表情键盘