iOS開發之1:1比例仿微信表情鍵盤

今天剛好520,單身的iOS狗扎心不O(∩_∩)O哈哈~ 好了,不扯犢子,進入話題

公司最近正在開發直播項目,為了省錢接了一個聽都沒聽過的直播,emmmm,不想多少,接入了各種問題,唯一頭疼的就是表情鍵盤,剛開始網上摸爬滾打,不是沒設配iPhoneX以上的設備,就是動畫寫的不盡人意,開發接入尾聲時間,忽然想起之前接過一個私活,騰訊云直播里面有表情鍵盤,果斷pod一下,把鍵盤單拎出來,各種改各種搓,終于在快下班時候成功了,哈哈,在此分享給哪些爬坑的小伙伴們,同時感謝騰訊云前輩們造的輪子
8`ZEOT}%V7WMQWFLJRH5QHM.jpg

  • 效果圖


    未命名.gif
簡單修了一些業務上的bug
  1. 修復了表情鍵盤只能刪除表情的問題
  2. 刪除了一些騰訊云里面無用的文件以及代碼
  3. 支持自定義表情

站在前輩們的肩膀上開發:

  • 激動人人心的時候到來了,上面都是扯犢子,下面咱們看看怎么用吧 上硬菜O(∩_∩)O哈哈~
    _inputController = [[LLInputController alloc] init];
   _inputController.view.frame = CGRectMake(0, self.view.frame.size.height - TTextView_Height - Bottom_SafeHeight, self.view.frame.size.width, TTextView_Height + Bottom_SafeHeight);
    _inputController.view.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    _inputController.delegate = self;
    [self addChildViewController:_inputController];
    [self.view addSubview:_inputController.view];
  • 是不是驚了 就這么簡單
    1.png
  • 當然還要遵循代理 實現代理方法
- (void)inputController:(LLInputController *)inputController didChangeHeight:(CGFloat)height
{
    __weak typeof(self) ws = self;
    [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        CGRect msgFrame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - CGRectGetHeight(self.inputController.view.frame));
        msgFrame.size.height = ws.view.frame.size.height - height;
        CGRect inputFrame = ws.inputController.view.frame;
        inputFrame.origin.y = msgFrame.origin.y + msgFrame.size.height;
        inputFrame.size.height = height;
        ws.inputController.view.frame = inputFrame;

    } completion:nil];
}
- (void)inputController:(LLInputController *)inputController didSendMessage:(id)msg {
    if ([msg isKindOfClass:[NSString class]]) {
        NSLog(@"發送的文本消息 內容====%@",msg);
        return;
    }
    if ([msg isKindOfClass:[AVURLAsset class]]) {
       AVURLAsset *audioAsset = msg;
        int duration = (int)CMTimeGetSeconds(audioAsset.duration);
        int length = (int)[[[NSFileManager defaultManager] attributesOfItemAtPath:[audioAsset.URL path] error:nil] fileSize];
        NSLog(@"發送的語音消息 語音長度====%d 長度== %d",duration,length);
        
        return;
    }
}
- (void)inputController:(LLInputController *)inputController didSelectMoreCell:(LLInputMoreCell *)cell {
    if ([cell.data.title isEqualToString:@"相冊"]) {
        NSLog(@"點擊了相冊");
        return;
    }
    if ([cell.data.title isEqualToString:@"拍照"]) {
        NSLog(@"點擊了拍照");
        return;
    }
}
191A69CF-1854-4A26-9B82-2869F0B4BBBB.png
  • 結束啦
  • 最后附上demo
https://github.com/lanyuzx/VXKeyborad/tree/master
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。