<WGKeyboard> 模仿微信的一款鍵盤

不廢話直接看效果

1.gif

使用方法

  1. 引用頭文件后, 直接上代碼:
    UITableView *TB = [[UITableView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:TB];
    TB.dataSource = self;
    TB.delegate = self;
    
    WGKeyboard *keyboard = [WGKeyboard keyboardWithType:KeyboardTypeChat];
    [self.view addSubview:keyboard];
    _keyboard = keyboard;
    keyboard.assoTB = TB;
    keyboard.delegate = self;
    keyboard.dataSource = self;
    keyboard.recordRootPath = NSTemporaryDirectory();
    keyboard.placeholder = @"嘻嘻";
  1. 實現(xiàn)對應(yīng)的數(shù)據(jù)源方法:
/**
 獲取表情包
 
 @param keyboard 自身
 @return 表情包
 */
- (nullable NSArray<StikerPackageModel *> *)stikerPackagesInKeyboard:(nonnull __kindof WGKeyboard *)keyboard {
    
    NSMutableArray *arrM = @[].mutableCopy;
    for (int i = 0; i < 4; i++) {
        
        StikerPackageModel *model = [StikerPackageModel new];
        [arrM addObject:model];
        
        if (i == 0) {
            
            model.stikerPackageType = StikerPackageTypeEmoji;
            model.localCover = [UIImage imageNamed:@"expression_common"];
            
            NSString *path = [[NSBundle mainBundle] pathForResource:@"emoji" ofType:@"plist"];
            NSArray *arr = [[NSArray alloc] initWithContentsOfFile:path];
            NSMutableArray<StikerInfoModel *> *emojiArrM = @[].mutableCopy;
            [arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                StikerInfoModel *stikerModel = [StikerInfoModel new];
                stikerModel.stikerType = StikerTypeEmoji;
                stikerModel.stikerTitle = obj;
                
                [emojiArrM addObject:stikerModel];
            }];
            model.stikers = emojiArrM;
        }
        else if (i == 1) {
            
            model.stikerPackageType = StikerPackageTypeColl;
            model.localCover = [UIImage imageNamed:@"expression_collect"];
            
            NSMutableArray<StikerInfoModel *> *customArrM = @[].mutableCopy;
            for (int k = 0; k < 1; k++) {
                
                if (k == 0) {
                    
                    StikerInfoModel *stikerModel = [StikerInfoModel new];
                    stikerModel.stikerType = StikerTypeAdd;
                    stikerModel.stikerTitle = @"look_add";
                    
                    [customArrM addObject:stikerModel];
                }
                else {
                    
                    StikerInfoModel *stikerModel = [StikerInfoModel new];
                    stikerModel.stikerType = StikerTypeCustom;
                    stikerModel.stikerCover = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559805949&di=f8b76f631546bd460f75b23eeaeae14d&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F01acc45607d5826ac7251df87e05b8.jpg%401280w_1l_2o_100sh.png";
                    stikerModel.stiker = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559310678046&di=2b90e719e298535e22aa21c8e6415ec3&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fq_mini%2Cc_zoom%2Cw_640%2Fupload%2F20170601%2Fc24155302f6c43e5a9c4fb26d9c3d888_th.jpg";
                    
                    [customArrM addObject:stikerModel];
                }
            }
            model.stikers = customArrM;
        }
        else if (i == 2) {
            
            model.stikerPackageType = StikerPackageTypeOffi;
            model.netCover = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559806211&di=3d332f727fa4cf054e79c3c833cc1a37&imgtype=jpg&er=1&src=http%3A%2F%2Fimg1.cache.netease.com%2Fcatchpic%2F8%2F87%2F87BBEB021F6DE57DF0D350B6782D1F7F.JPG";
            
            NSMutableArray<StikerInfoModel *> *customArrM = @[].mutableCopy;
            for (int j = 0; j < 10; j++) {
                
                StikerInfoModel *stikerModel = [StikerInfoModel new];
                stikerModel.stikerType = StikerTypeCustom;
                stikerModel.stikerTitle = @"阿古";
                stikerModel.stikerCover = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559728968&di=49d63ed3f7d9f518805f59cd23d6bda4&imgtype=jpg&er=1&src=http%3A%2F%2Fimg4.duitang.com%2Fuploads%2Fitem%2F201607%2F17%2F20160717061822_dJvkX.png";
                stikerModel.stiker = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559310428842&di=c22715e59de06f31ab1f6ae0f24a59cf&imgtype=0&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170713%2F84a1d0aec22c43f894c294a4e2de9787.png";
                
                [customArrM addObject:stikerModel];
            }
            model.stikers = customArrM;
        }
        else {
            
            model.stikerPackageType = StikerPackageTypeOffi;
            model.netCover = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559806266&di=f266e55a4d75e34eac12eae3a4bfe6c9&imgtype=jpg&er=1&src=http%3A%2F%2Fimg.zcool.cn%2Fcommunity%2F0144d45b49b077a8012036be44456c.jpeg%40260w_195h_1c_1e_1o_100sh.jpg";
            
            NSMutableArray<StikerInfoModel *> *customArrM = @[].mutableCopy;
            for (int j = 0; j < 10; j++) {
                
                StikerInfoModel *stikerModel = [StikerInfoModel new];
                stikerModel.stikerType = StikerTypeCustom;
                stikerModel.stikerTitle = @"阿超";
                stikerModel.stikerCover = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1559806330&di=7a04cde5a7b391a657863098df299586&imgtype=jpg&er=1&src=http%3A%2F%2Fi2.17173cdn.com%2F2fhnvk%2FYWxqaGBf%2Fcms3%2FoDPDPCbkBpCvpso.png";
                stikerModel.stiker = @"http://photocdn.sohu.com/20150721/mp23627612_1437451852870_2.gif";
                
                [customArrM addObject:stikerModel];
            }
            model.stikers = customArrM;
        }
    }
    return arrM;
}
  1. 有需要的話可以實現(xiàn)對應(yīng)的代理方法:
/**
 選擇自定義表情回調(diào)
 
 @param keyboard 自身
 @param customStiker 所選自定義表情
 */
- (void)keyboard:(nonnull __kindof WGKeyboard *)keyboard didSelectCustomStiker:(nonnull StikerInfoModel *)customStiker;

/**
 點(diǎn)擊添加表情回調(diào)
 
 @param keyboard 自身
 */
- (void)didSelectAddStikerWithKeyboard:(nonnull __kindof WGKeyboard *)keyboard;

/**
 發(fā)送按鈕點(diǎn)擊回調(diào)

 @param keyboard 自身
 @param content 內(nèi)容
 */
- (void)keyboard:(nonnull __kindof WGKeyboard *)keyboard didClickSendWithContent:(nonnull NSString *)content;

/**
 錄音開始回調(diào)

 @param keyboard 自身
 */
- (void)audioRecordDidStartWithKeyboard:(nonnull __kindof WGKeyboard *)keyboard;

/**
 錄音完成回調(diào)
 
 @param keyboard 自身
 @param path 音頻文件路徑
 @param duration 時長
 */
- (void)keyboard:(nonnull __kindof WGKeyboard *)keyboard audioRecordDidFinishWithPath:(nonnull NSString *)path duration:(NSTimeInterval)duration;

/**
 錄音取消回調(diào)
 
 @param keyboard 自身
 */
- (void)audioRecordDidCancelWithKeyboard:(nonnull __kindof WGKeyboard *)keyboard;

/**
 選擇更多元素回調(diào)
 
 @param keyboard 自身
 @param type 更多元素類型
 */
- (void)keyboard:(nonnull __kindof WGKeyboard *)keyboard didSelectMoreItemWithType:(MoreItemType)type;

/**
 監(jiān)聽內(nèi)容為空時刪除鍵點(diǎn)擊
 
 @param keyBoard 自身
 */
- (void)didDeleteBackwardWhenAvoidWithKeyBoard:(nonnull __kindof WGKeyboard *)keyBoard;

最后附上github地址
https://github.com/Veeco/WGKeyboard

最近忙著人生大事很少回復(fù)希望大家多多見諒, 如有意見或其它想法可以多多提出, 謝謝!
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容