1.環(huán)信(V3.3.5(2017-10-24)以前版本)聊天界面的iPhoneX屏幕適配

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是否展開判定
//是否已經(jīng)隱藏底部tool

@property (nonatomic, assign) BOOL isHiddenChatTool; 

//2.此處判定 主要是針對 有聊天數(shù)據(jù)的時候,最底部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.主要是 發(fā)送消息后 有關界面處理

#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
//監(jiān)聽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];
}

//即將開始 輸入送信息監(jiān)聽
- (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;
}
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容