环信

1.环信(V3.3.5(2017-10-24)以前版本)聊天界面

2017-10-26  本文已影响43人  淡闲星草

1.iPhoneX 宏定义

#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define iOS11 ([[UIDevice currentDevice].systemVersion doubleValue] >= 11.0)

2.聊天界面适配

#import "EaseMessageViewController.h"

//1.添加chatToolbar是否展开判定
//是否已经隐藏底部tool

@property (nonatomic, assign) BOOL isHiddenChatTool; 

//2.此处判定 主要是针对 有聊天数据的时候,最底部cell被chatToolbar遮挡问题

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    self.isViewDidAppear = YES;
    [[EaseSDKHelper shareHelper] setIsShowingimagePicker:NO];
    
    if (self.scrollToBottomWhenAppear) {
        [self _scrollViewToBottom:NO];
    }
    self.scrollToBottomWhenAppear = YES;
    
 //3.针对 ipnoneX 的适配
    if (iPhoneX) {
        //1.table
        [UIView animateWithDuration:0.3 animations:^{
            CGRect rect = self.tableView.frame;
            rect.origin.y = 0;
            rect.size.height = self.view.frame.size.height - 46;
            rect.size.height = self.view.frame.size.height - 46 - 20;
            self.tableView.frame = rect;
        }];
        [self _scrollViewToBottom:NO];
   
        //2.chatToolbar
        self.chatToolbar.frame = CGRectMake(0, self.view.frame.size.height - [EaseChatToolbar defaultHeight]-20, self.view.frame.size.width, [EaseChatToolbar defaultHeight]+20);
    }
}

3.主要是 发送消息后 有关界面处理

#pragma mark - GestureRecognizer
//点击 手势 隐藏键盘
-(void)keyBoardHidden:(UITapGestureRecognizer *)tapRecognizer
{
    if (iPhoneX) {
      self.isHiddenChatTool = YES;
    }
    
    if (tapRecognizer.state == UIGestureRecognizerStateEnded) {
        [self.chatToolbar endEditing:YES];
        if (iPhoneX) {
            self.chatToolbar.frame = CGRectMake(0, self.view.frame.size.height - [EaseChatToolbar defaultHeight]-20, self.view.frame.size.width, [EaseChatToolbar defaultHeight]+20);

        }
        
    }
}
#pragma mark - EMChatToolbarDelegate
//监听chatBarTool  frame变化
- (void)chatToolbarDidChangeFrameToHeight:(CGFloat)toHeight
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect rect = self.tableView.frame;
       
        rect.origin.y = 0;
        rect.size.height = self.view.frame.size.height - toHeight;
        if (self.isHiddenChatTool == YES && iPhoneX) {
            rect.size.height = self.view.frame.size.height - toHeight - 20;
        }
  
        self.tableView.frame = rect;
    }];
    
    [self _scrollViewToBottom:NO];
}

//即将开始 输入送信息监听
- (void)inputTextViewWillBeginEditing:(EaseTextView *)inputTextView
{
    if (iPhoneX ) {
       self.isHiddenChatTool = NO;
    }
    
    if (_menuController == nil) {
        _menuController = [UIMenuController sharedMenuController];
    }
    [_menuController setMenuItems:nil];
}

4.输入信息后 刷新界面 感觉刷新多次错乱问题

主要是 针对 iOS11的UITableView 适配

#import "EaseRefreshTableViewController.h"
- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:self.style];
    _tableView.accessibilityIdentifier = @"table_view";
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = self.defaultFooterView;
    [self.view addSubview:_tableView];
    
    if (iOS11) {
        _tableView.estimatedRowHeight = 0;
        _tableView.estimatedSectionHeaderHeight = 0;
        _tableView.estimatedSectionFooterHeight = 0;
       
    }
    _page = 0;
    _showRefreshHeader = NO;
    _showRefreshFooter = NO;
    _showTableBlankView = NO;
}
上一篇下一篇

猜你喜欢

热点阅读