1. 程式人生 > >ios開發之--仿(微信)自定義表情鍵盤

ios開發之--仿(微信)自定義表情鍵盤

lai signed avi 創建 不能 url div load mps

先附上demo:https://github.com/hgl753951/CusEmoji.git

效果圖如下:

技術分享圖片

先說下具體的實現功能:

1,本地加載了一些H5的代碼,直接使用webview的load方法加載出來的

2,獲取web的動態高度,然後創建tableview,把webview加到一個tableview的headerview上,

3,實現cell的自定義高度,是用xib實現的

4,評論功能的實現,自定表情鍵盤,可以發送表情,文字等相關信息

這個demo裏面有2個效果,第一個是我自己寫的很粗糙,沒有加表情鍵盤,第二個是加了表情鍵盤的。

話不多了,代碼如下:

.h

//
//  hMyDetailViewController.h
// 評論Test // // Created by 伯駒網絡 on 2017/11/30. // Copyright ? 2017年 Nicholas. All rights reserved. // #import <UIKit/UIKit.h> #import "XHMessageInputView.h" #import "XHEmotionManagerView.h" #define EMOJI_CODE_TO_SYMBOL(x) ((((0x808080F0 | (x & 0x3F000) >> 4) | (x & 0xFC0) << 10) | (x & 0x1C0000) << 18) | (x & 0x3F) << 24); #define
KEYBOARD_height 50.0; @interface hMyDetailViewController : UIViewController<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate,XHMessageInputViewDelegate,XHEmotionManagerViewDelegate, XHEmotionManagerViewDataSource> /** * 用於顯示發送消息類型控制的工具條,在底部 */ @property (nonatomic,strong)XHMessageInputView
*inputView; @property (nonatomic, assign) XHInputViewType textViewInputViewType; @property (nonatomic, assign) XHMessageInputViewStyle inputViewStyle; @property (nonatomic, strong) NSArray *emotionManagers; @property (strong, nonatomic) NSDictionary * facesDic; @property (strong, nonatomic) NSArray *facesAry; @property (nonatomic,strong) NSArray *faceNUmArr; /** * 管理第三方gif表情的控件 */ @property (nonatomic, weak, readonly) XHEmotionManagerView *emotionManagerView; /** * 是否支持發送表情 */ @property (nonatomic, assign) BOOL allowsSendFace; // default is YES /** * 是否允許手勢關閉鍵盤,默認是允許 */ @property (nonatomic, assign) BOOL allowsPanToDismissKeyboard; // default is YES @end

.m

//
//  hMyDetailViewController.m
//  評論Test
//
//  Created by 伯駒網絡 on 2017/11/30.
//  Copyright ? 2017年 Nicholas. All rights reserved.
//

#import "hMyDetailViewController.h"
#import "Masonry.h"
#import "ContentCell.h"
#import "hModel.h"

@interface hMyDetailViewController ()
@property (nonatomic,strong)UIWebView *webView;
@property (nonatomic,strong)UIView *headerView;
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;
@property (nonatomic,strong)NSDictionary *dict;

@property (nonatomic, weak, readwrite) XHEmotionManagerView *emotionManagerView;
@property (nonatomic, assign) CGFloat keyboardViewHeight;

@end

@implementation hMyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    _dataArray = [NSMutableArray array];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"詳情";
    _dict =  @{
               @"photoURL":@"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2077447965,2640702927&fm=27&gp=0.jpg",
               @"user_name":@"李三",
               @"info":@"北國風光,千裏冰封,萬裏雪飄。望長城內外,惟余莽莽;大河上下,頓失滔滔。山舞銀蛇,原馳蠟象,欲與天公試比高。須晴日,看紅裝素裹,分外妖嬈。江山如此多嬌,引無數英雄競折腰。 惜秦皇漢武,略輸文采;唐宗宋祖,稍遜風騷。 一代天驕,成吉思汗,只識彎弓射大雕。 俱往矣,數風流人物,還看今朝。",
               @"nowDate":@"1485163320"
               };
    
    self.keyboardViewHeight = (kXHEmotionImageViewSize+15)*3+kXHEmotionPageControlHeight+10;
    //增加監聽,當鍵改變時時收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
    //增加監聽,當鍵退出時收出消息
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:)
                                                 name:UIKeyboardWillHideNotification    object:nil];
    
    NSString *emotionPath = [[NSBundle mainBundle] pathForResource:@"emotion" ofType:@"plist"];
    NSString *emotionImagePath = [[NSBundle mainBundle] pathForResource:@"emotionImage1" ofType:@"plist"];
    self.facesDic = [[NSDictionary alloc]initWithContentsOfFile:emotionImagePath];
    self.faceNUmArr = [[NSArray alloc]initWithContentsOfFile:emotionPath];
    
    NSMutableArray *lastArr = [[NSMutableArray alloc]initWithCapacity:0];
    for (NSNumber  *str in self.faceNUmArr) {
        int aaa = [str intValue];
        int sym = EMOJI_CODE_TO_SYMBOL(aaa);
        NSString *emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym) encoding:NSUTF8StringEncoding];
        [lastArr addObject:emoT];
    }
    self.facesAry = lastArr;
    
    [self initInputView];
}

-(void)keyboardWillShow:(NSNotification *)aNotification
{
    //獲取鍵盤的高度
    NSDictionary *userInfo = [aNotification userInfo];
    NSValue *aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    int height = keyboardRect.size.height;
    [UIView animateWithDuration:0.1 animations:^{
        CGRect tableFrame = self.tableView.frame;
        tableFrame.size.height = MainScreen_height-NavigationHeight-50-height;
        self.tableView.frame = tableFrame;
        CGRect rect = self.inputView.frame;
        rect.origin.y = MainScreen_height-height-50;
        self.inputView.frame = rect;
    }];
}

-(void)keyboardWillHide:(NSNotification *)aNotification
{
    CGRect tableFrame = self.tableView.frame;
    tableFrame.size.height = MainScreen_height-NavigationHeight-50;
    self.tableView.frame = tableFrame;
    
    CGRect rect = self.inputView.frame;
    rect.origin.y = MainScreen_height-45;
    self.inputView.frame = rect;
}

-(void)initInputView
{
    
    
    // 設置Message TableView 的bottom edg
    
    CGFloat inputViewHeight = KEYBOARD_height;
    // 輸入工具條的frame
    CGRect inputFrame = CGRectMake(0.0f,
                                   self.view.frame.size.height - inputViewHeight,
                                   self.view.frame.size.width,
                                   inputViewHeight);
    // 初始化輸入工具條
    XHMessageInputView *inputView = [[XHMessageInputView alloc] initWithFrame:inputFrame];
    inputView.allowsSendFace = YES;
    inputView.allowsSendVoice = NO;
    inputView.allowsSendMultiMedia = NO;
    inputView.delegate = self;
    [self.view addSubview:inputView];
    [self.view bringSubviewToFront:inputView];
    _inputView = inputView;
    
    self.inputView.backgroundColor = Color(248, 248, 248);
    
    NSMutableArray *emotionManagers = [NSMutableArray array];
    for (NSInteger i = 0; i < 10; i ++) {
        XHEmotionManager *emotionManager = [[XHEmotionManager alloc] init];
        emotionManager.emotionName = nil;
        NSMutableArray *emotions = [NSMutableArray array];
        for (NSInteger j = 0; j < self.facesAry.count; j ++) {
            XHEmotion *emotion = [[XHEmotion alloc] init];
            NSString * tmpStr = [self.facesAry objectAtIndex:j];
            emotion.emotionStr = tmpStr;
            if (j==20) {
                emotion.emotionStr = @"";
            }
            if (j==41) {
                emotion.emotionStr = @"";
            }
            if (j==62) {
                emotion.emotionStr = @"";
            }
            if (j==83) {
                emotion.emotionStr = @"";
            }
            if (j==94) {
                emotion.emotionStr = @"";
            }
            [emotions addObject:emotion];
        }
        emotionManager.emotions = emotions;
        [emotionManagers addObject:emotionManager];
    }
    self.emotionManagers = emotionManagers;
    [self.emotionManagerView reloadData];
    
    [self createView];
    [self creatWebView];
}

- (XHEmotionManagerView *)emotionManagerView {
    
    if (!_emotionManagerView) {
        XHEmotionManagerView *emotionManagerView = [[XHEmotionManagerView alloc] initWithFrame:CGRectMake(0, MainScreen_height, MainScreen_width, self.keyboardViewHeight)];
        emotionManagerView.delegate = self;
        emotionManagerView.dataSource = self;
        emotionManagerView.backgroundColor = [UIColor colorWithWhite:0.961 alpha:1.000];
        emotionManagerView.alpha = 1.0;
        [self.view addSubview:emotionManagerView];
        _emotionManagerView = emotionManagerView;
    }
    
    [self.view bringSubviewToFront:_emotionManagerView];
    return _emotionManagerView;
}



-(void)creatWebView
{
    self.webView = [UIWebView new];
    self.webView.backgroundColor = [UIColor clearColor];
    self.webView.delegate = self;
    self.webView.userInteractionEnabled = NO;
    self.webView.scrollView.scrollEnabled = NO;
    NSLog(@"html====%@",[[self dataArray] valueForKey:@"info"]);
    NSString *title=@"韓寒《後會無期》奇葩的吸金3秘籍";
    
    NSString *linkStr=[NSString stringWithFormat:@"<a href=‘%@‘>我的博客</a> <a href=‘%@‘>原文</a>",@"http://blog.csdn.net/wildcatlele",@"http://jincuodao.baijia.baidu.com/article/26059"];
    
    NSString *p1=@"韓寒《後會無期》的吸金能力很讓我驚訝!8月12日影片票房已成功沖破6億大關。而且排片量仍保持10 以上,以日收千萬的速度穩步向七億進軍。";
    
    NSString *p2=@"要知道,《後會無期》不是主流類型片,是一個文藝片。不像《小時代》,是一個商業主流的偶像電影。";
    
    NSString *image2=[NSString stringWithFormat:@"<img src=‘%@‘  height=‘280‘ width=‘375‘ />",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509537524520&di=8c2dc517fd7e80ca11a541b52b99fa75&imgtype=0&src=http%3A%2F%2Fpic42.nipic.com%2F20140606%2F18939690_111450345176_2.jpg"];
    
    NSString *image3=[NSString stringWithFormat:@"<img src=‘%@‘  height=‘280‘ width=‘375‘ />",@""];
    
    NSString *image4=[NSString stringWithFormat:@"<img src=‘%@‘  height=‘280‘ width=‘375‘ />",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509537524520&di=8c2dc517fd7e80ca11a541b52b99fa75&imgtype=0&src=http%3A%2F%2Fpic42.nipic.com%2F20140606%2F18939690_111450345176_2.jpg"];
    
    NSString *image5=[NSString stringWithFormat:@"<img src=‘%@‘  height=‘280‘ width=‘375‘ />",@"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1509537524520&di=8c2dc517fd7e80ca11a541b52b99fa75&imgtype=0&src=http%3A%2F%2Fpic42.nipic.com%2F20140606%2F18939690_111450345176_2.jpg"];
    
    NSString *p3=@"太奇葩了!有人說,這是中國電影市場的紅利,是粉絲電影的成功。但是,有一部投資3000萬的粉絲電影《我就是我》,有明星,制作也不錯,基本上是慘敗。";
    
    NSString *p4=@"《後會無期》賣的不是好故事,是優越感。特別是針對80、90後的人群,你有沒有發現,看《後會無期》比看《小時代3》有明顯的優越感。故事雖然一般,但是很多人看完後,會在微博、微信上曬照片。所以說,對一個族群靠的不是廣度,而是深度。<br>        很兇殘,值得大家借鑒。韓寒《後會無期》還有什麽秘密武器,歡迎《後會無期》團隊或相關方爆料,直接留言即可,有料的可以送黎萬強親筆簽名的《參與感》一書。";
    //初始化和html字符串
    NSString *htmlURlStr=[NSString stringWithFormat:@"<body style=‘background-color:#EBEBF3‘><h2>%@</h2><p>%@</p> <p>%@ </p> <br><p> %@</p> <p>%@</p>%@<p>%@%@%@%@</p></body>",title,linkStr,p1,p2,p3,image2,image3,image4,image5,p4];
    [self.webView loadHTMLString:htmlURlStr baseURL:nil];
    
    [_headerView addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(@0);
        make.height.equalTo(@50);
    }];
}

-(void)createView
{
    _headerView  = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 1)];
    _headerView.alpha=0;
    _headerView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:_headerView];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    CGRect newFarme = webView.frame;
    newFarme.size.height = actualSize.height;
    NSLog(@"ssssss==%f",newFarme.size.height);
    [self.webView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(newFarme.size.height));
    }];
    
    _headerView.frame = CGRectMake(0, 0, kWidth, newFarme.size.height);
    NSLog(@"HEAD======%f",_headerView.bounds.size.height);
    _headerView.alpha = 1;
    [self creatTableView];
}

-(void)creatTableView
{
    self.tableView =[[UITableView alloc]initWithFrame:CGRectMake(0, 64, kWidth, self.view.bounds.size.height-70-44) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableHeaderView=_headerView;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.estimatedRowHeight = 300;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    [self.tableView registerNib:[UINib nibWithNibName:@"ContentCell" bundle:nil] forCellReuseIdentifier:@"ContentCell"];
    [self.view addSubview:self.tableView];
}

-(void)sendMessage:(NSString *)text
{
    hModel *model = [[hModel alloc] init];
    model.message =_inputView.inputTextView.text;
    
    if (model.message != nil && [model.message isEqualToString:@""]) {
        [UIAlertView bk_showAlertViewWithTitle:@"溫馨提醒" message:@"輸入不能為空" cancelButtonTitle:@"取消" otherButtonTitles:nil handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
            
        }];
    }else
    {
//        [_tf resignFirstResponder];
        [_dataArray addObject:model];
        NSLog(@"--%@",_dataArray);
        [_tableView reloadData];
        
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_dataArray.count-1 inSection:0];
        [_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
        
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//鍵盤下落
        self.inputView.inputTextView.text = @"";
        [self.inputView.sendBtn setImage:[UIImage imageNamed:@"ico_Send_message_cannot"] forState:UIControlStateNormal];
        self.tableView.frame = CGRectMake(0, NavigationHeight, MainScreen_width, MainScreen_height-50.0f-NavigationHeight);
        self.textViewInputViewType = XHInputViewTypeEmotion;
        [self layoutOtherMenuViewHiden:YES];//表情鍵盤下落
    }
    
}

#pragma mark - XHEmotionManagerView DataSource

- (NSInteger)numberOfEmotionManagers {
    return self.emotionManagers.count;
}

- (XHEmotionManager *)emotionManagerForColumn:(NSInteger)column {
    return [self.emotionManagers objectAtIndex:column];
}

- (NSArray *)emotionManagersAtManager {
    return self.emotionManagers;
}

#pragma mark - XHMessageInputView Delegate

- (void)inputTextViewWillBeginEditing:(XHMessageTextView *)messageInputTextView {
    
    self.textViewInputViewType = XHInputViewTypeText;
}

- (void)inputTextViewDidBeginEditing:(XHMessageTextView *)messageInputTextView {
    
}
- (void)didSendTextAction:(NSString *)text {
    
    [self sendMessage:text];
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]){ //判斷輸入的字是否是回車,即按下return
        //在這裏做你響應return鍵的代碼
        [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
        return NO; //這裏返回NO,就代表return鍵值失效,即頁面上按下return,不會出現換行,如果為yes,則輸入頁面會換行
    }
    
    return YES;
}

#pragma mark - XHEmotionManagerView Delegate

- (void)didSelecteEmotion:(XHEmotion *)emotion atIndexPath:(NSIndexPath *)indexPath {
    //    self.inputStr = self.inputView;
    NSString *newStr;
    if (indexPath.row == 20||indexPath.row==41||indexPath.row==62||indexPath.row==83) {
        if (self.inputView.inputTextView.text.length>1) {
            CLog(@"===isEqualToString:]====%lu",(unsigned long)self.inputView.inputTextView.text.length);
            if ([self.facesAry containsObject:[self.inputView.inputTextView.text substringFromIndex:self.inputView.inputTextView.text.length-2]]) {
                CLog(@"刪除emoji %@",[self.inputView.inputTextView.text substringFromIndex:self.inputView.inputTextView.text.length-2]);
                
                newStr=[self.inputView.inputTextView.text substringToIndex:self.inputView.inputTextView.text.length-2];
            }else{
                CLog(@"刪除文字%@",[self.inputView.inputTextView.text substringFromIndex:self.inputView.inputTextView.text.length-1]);
                newStr=[self.inputView.inputTextView.text substringToIndex:self.inputView.inputTextView.text.length-1];
            }
            self.inputView.inputTextView.text=newStr;
        }else{
            newStr=@"";
            self.inputView.inputTextView.text = newStr;
        }
        
    }else{
        NSString *faceNumStr = [self.faceNUmArr objectAtIndex:indexPath.row];
        NSArray *allKeys = [self.facesDic allKeysForObject:faceNumStr];
        NSString *faceStr = [self.facesAry objectAtIndex:indexPath.row];
        if ([allKeys count]>0) {
            NSString *valueStr = [allKeys objectAtIndex:0];
            [self didSendEmotionMessageWithEmotionPath:faceStr faceStr:valueStr];
        }
    }
    
}

- (NSString *)checkTheChatStringReplaceFace:(NSString *)theString
{
    NSArray * arr = [theString componentsSeparatedByString:@"["];
    for (int i= 0; i<[arr count]; i++) {
        NSRange range=[theString rangeOfString:@"["];
        NSRange range1=[theString rangeOfString:@"]"];
        //判斷當前字符串是否還有表情的標誌。
        if (range.length>0 && range1.length>0) {
            
            NSString * strTmp = [theString substringWithRange:NSMakeRange(range.location, range1.location+1-range.location)];
            NSString * valueStr = [self.facesDic objectForKey:strTmp];
            int aaa = [valueStr intValue];
            int sym = EMOJI_CODE_TO_SYMBOL(aaa);
            NSString *emoT = [[NSString alloc] initWithBytes:&sym length:sizeof(sym) encoding:NSUTF8StringEncoding];
            theString = [theString stringByReplacingOccurrencesOfString:strTmp withString:emoT];
        }
        
    }
    
    return theString;
}
- (void)didSendEmotionMessageWithEmotionPath:(NSString *)emotionPath faceStr:(NSString *)str {
    
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isSend"];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"selectSendBtn"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [self.inputView.sendBtn setImage:[UIImage imageNamed:@"ico_Send_message"] forState:UIControlStateNormal];
    
    self.inputView.multiMediaSendButton.hidden = YES;
    self.inputView.sendBtn.hidden = NO;
    self.inputView.inputTextView.text = [self.inputView.inputTextView.text stringByAppendingString:emotionPath];
    
    DLog(@"send emotionPath:%@", self.inputView.inputTextView.text);
    
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
    
    //    self.isUserScrolling = YES;
    UIMenuController *menu = [UIMenuController sharedMenuController];
    if (menu.isMenuVisible) {
        [menu setMenuVisible:NO animated:YES];
    }
    self.textViewInputViewType = XHInputViewTypeEmotion;
    [self layoutOtherMenuViewHiden:YES];
    
    
    //    if (self.textViewInputViewType != XHInputViewTypeNormal && self.textViewInputViewType != XHInputViewTypeText) {
    //        [self layoutOtherMenuViewHiden:YES];
    //    }
}
- (void)didSendFaceAction:(BOOL)sendFace {
    if (sendFace) {
        self.textViewInputViewType = XHInputViewTypeEmotion;
        [self layoutOtherMenuViewHiden:NO];
    } else {
        
        self.textViewInputViewType = XHInputViewTypeEmotion;
        [self layoutOtherMenuViewHiden:YES];
        
    }
}

#pragma mark - Other Menu View Frame Helper Mehtod

- (void)layoutOtherMenuViewHiden:(BOOL)hide {
    
    NSLog(@"%@",hide?@"YES":@"NO");
    
    [self.inputView.inputTextView resignFirstResponder];
    
    [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
        __block CGRect otherMenuViewFrame;
        
        void (^InputViewAnimation)(BOOL hide) = ^(BOOL hide) {
            if (hide) {
                self.inputView.frame = CGRectMake(0, MainScreen_height-50.0f, MainScreen_width, 50);
                [self.view bringSubviewToFront:self.inputView];
                
            }else{
                [self.view bringSubviewToFront:self.inputView];
                CGRect rect = self.inputView.frame;
                rect.origin.y = MainScreen_height-self.keyboardViewHeight-50.0;
                self.inputView.frame = rect;
            }
        };
        
        void (^EmotionManagerViewAnimation)(BOOL hide) = ^(BOOL hide) {
            otherMenuViewFrame = self.emotionManagerView.frame;
            
            otherMenuViewFrame.origin.y = (hide ? MainScreen_height : (MainScreen_height - CGRectGetHeight(otherMenuViewFrame)));
            self.emotionManagerView.frame = otherMenuViewFrame;
            self.emotionManagerView.alpha = !hide;
            
        };
        if (hide) {
            switch (self.textViewInputViewType) {
                case XHInputViewTypeEmotion: {
                    EmotionManagerViewAnimation(hide);
                    break;
                }
                case XHInputViewTypeShareMenu: {
                    break;
                }
                default:
                    break;
            }
            
            
        } else {
            
            // 這裏需要註意block的執行順序,因為otherMenuViewFrame是公用的對象,所以對於被隱藏的Menu的frame的origin的y會是最大值
            switch (self.textViewInputViewType) {
                case XHInputViewTypeEmotion: {
                    // 1、先隱藏和自己無關的View
                    //                    ShareMenuViewAnimation(!hide);
                    // 2、再顯示和自己相關的View
                    EmotionManagerViewAnimation(hide);
                    break;
                }
                case XHInputViewTypeShareMenu: {
                    // 1、先隱藏和自己無關的View
                    EmotionManagerViewAnimation(!hide);
                    // 2、再顯示和自己相關的View
                    //                    ShareMenuViewAnimation(hide);
                    break;
                }
                default:
                    break;
            }
        }
        InputViewAnimation(hide);
    } completion:^(BOOL finished) {
        NSLog(@"我走了沒有");
    }];
}


//-(void)scrollViewDidScroll:(UIScrollView *)scrollView
//{
//    if (scrollView.contentOffset.y > 0) {
//        //展示
//        self.inputView.frame = CGRectMake(0, kHeight - 60, kWidth, 60);
//        self.tableView.frame = CGRectMake(0, 64, kWidth, self.view.bounds.size.height-70-44);
//        self.navigationController.navigationBarHidden = NO;
//        [_tf resignFirstResponder];
//    }else
//    {
//        //隱藏
//        self.inputView.frame = CGRectMake(0, kHeight, kWidth, 60);
//        self.tableView.frame = CGRectMake(0, 64, kWidth, self.view.bounds.size.height);
//        self.navigationController.navigationBarHidden = YES;
//        [_tf resignFirstResponder];
//    }
//}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ContentCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ContentCell"];
    if (!cell) {
        cell = [[ContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ContentCell"];
    }
    
    [cell.headerImg sd_setImageWithURL:[NSURL URLWithString:[_dict objectForKey:@"photoURL"]] placeholderImage:[UIImage imageNamed:PERSON_IMG]];
    cell.nameLab.text = [_dict objectForKey:@"user_name"];
    //    cell.contentLab.text = [_dict objectForKey:@"info"];
    cell.nowDateLab.text = [_dict objectForKey:@"nowDate"];
    hModel *model = _dataArray[indexPath.row];
    cell.contentLab.text = model.message;
    return cell;
}

//-(BOOL)textFieldShouldReturn:(UITextField *)textField
//{
//    [_tf resignFirstResponder];
//    return YES;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

邏輯很簡單也很清晰,先[self initInputView]-->[self createView];&& [self creatWebView];-->在webViewDidFinishLoad裏面走[self creatTableView];方法,動態高度是用Masonry實現的!希望能幫到大家,代碼是完整的,可以直接復制粘貼使用!demo和代碼沒有詳細整理,註釋也不多,後期我會完善的,加上回復等相關功能!

ios開發之--仿(微信)自定義表情鍵盤