Browse Source

聊天页面优化

桂欢 1 year ago
parent
commit
ee63a76eb6

+ 2 - 0
SLAiELTS/SLAiELTS/AppMarcos/YMConstMacro.h

@@ -106,4 +106,6 @@
 
 #define SLCol8E8E93      SLColor(@"#8E8E93")
 
+#define SLColF5F5F5      SLColor(@"#F5F5F5")
+
 #endif /* YMConstMacro_h */

+ 15 - 3
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/SLMessageViewController.m

@@ -137,12 +137,24 @@
     CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
     //计算控制器的view需要平移的距离
     CGFloat transformY = keyboardFrame.origin.y - kSCREEN_HEIGHT + kSafeAreaBottom;
+    
+    UICollectionView *scrollView = self.chatServiceView.messageView.messageCollectionView;
+
+    CGFloat messageMaxY = scrollView.contentSize.height;
+    //    CGFloat messageMaxY = [self.chatServiceView.messageView getBotttomCellMaxY];
+    CGFloat msgHeigh = kSCREEN_HEIGHT - kNavBarHeight - CGRectGetHeight(self.chatServiceView.chatBottomView.frame);
+    if (messageMaxY > msgHeigh) {
+        CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
+        [scrollView setContentOffset:bottomOffset animated:YES];
+    }
     //执行动画
-    CGFloat messageMaxY = [self.chatServiceView.messageView getBotttomCellMaxY];
     void (^animation)(void) = ^void(void) {
-        if (messageMaxY - transformY > kSCREEN_HEIGHT - kNavBarHeight - CGRectGetHeight(self.chatServiceView.chatBottomView.frame)) {
-            CGFloat transformY1 = -(messageMaxY - transformY - (kSCREEN_HEIGHT - kNavBarHeight - CGRectGetHeight(self.chatServiceView.chatBottomView.frame)));
+        if (messageMaxY - transformY > msgHeigh) {
+            CGFloat transformY1 = -(messageMaxY - transformY - msgHeigh);
             CGFloat mainTransformY = MAX(transformY1, transformY);//聊天view
+            if (messageMaxY < msgHeigh) {
+                mainTransformY -= 50.0;
+            }
             CGFloat bottomTransformY = transformY - mainTransformY;//输入view
             self.chatServiceView.transform = CGAffineTransformMakeTranslation(0, mainTransformY);
             self.chatServiceView.chatBottomView.transform = CGAffineTransformMakeTranslation(0,bottomTransformY);

+ 35 - 2
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/Views/IMMessageView/YMIMMessageCollectionView.m

@@ -12,6 +12,9 @@
 
 @interface YMIMMessageCollectionView()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate>
 
+@property (nonatomic, assign) BOOL scrollViewDidEnd;
+
+@property (nonatomic, assign) CGFloat scrollViewOfsetY;
 
 @end
 
@@ -69,6 +72,11 @@
 {
     dispatch_async(dispatch_get_main_queue(), ^{
         if (self.chatDataManager.count > 0) {
+//            UIScrollView * scrollView= self.messageCollectionView;
+//            CGPoint bottomOffset = CGPointMake(0, scrollView.contentSize.height - scrollView.bounds.size.height);
+//            self.scrollViewDidEnd = NO;
+//            [scrollView setContentOffset:bottomOffset animated:YES];
+            
             NSIndexPath *endIndex = [NSIndexPath indexPathForItem:self.chatDataManager.count - 1 inSection:0];
             [self.messageCollectionView scrollToItemAtIndexPath:endIndex atScrollPosition:UICollectionViewScrollPositionBottom animated:animated];
         }
@@ -348,9 +356,34 @@
     }
     return CGSizeMake(kSCREEN_WIDTH, height);
 }
+//
+//- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
+//{
+//    return [[UICollectionReusableView alloc] initWithFrame:CGRectZero];
+//}
+//
+//
+//- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
+//    return CGSizeZero;
+//}
+
+- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
+    if (self.scrollViewDidEnd && self.scrollViewOfsetY - scrollView.contentOffset.y > 15) {
+        self.scrollViewDidEnd = NO;
+        self.scrollViewOfsetY = 0.0f;
+        [self.viewController.view endEditing:YES];
+    }
+}
 
-- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
-{
+- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
+    CGFloat ty = self.superview.transform.ty;
+    if (ty < 0) {
+        self.scrollViewDidEnd = YES;
+        self.scrollViewOfsetY = scrollView.contentOffset.y;
+    }
+}
+
+- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
     
 }
 

+ 10 - 1
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/Views/YMChatBottomView.m

@@ -34,7 +34,7 @@ static const NSInteger btnTag = 20000;
 
 - (void)confignUI
 {
-    self.backgroundColor = [UIColor colorFormString:@"#F3F4F4"];
+    self.backgroundColor = SLColF5F5F5;
     [self.textBgView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.left.right.equalTo(self);
         make.top.mas_equalTo(8);
@@ -73,6 +73,14 @@ static const NSInteger btnTag = 20000;
     dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
         [self btnClick:self.leftBtn];
     });
+    
+    UIView *lineView = [[UIView alloc] initWithFrame:CGRectZero];
+    [self addSubview:lineView];
+    lineView.backgroundColor = [UIColor colorWithRed:220 / 255.0 green:220 / 255.0 blue:220 / 255.0 alpha:1.0];
+    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
+        make.left.right.top.equalTo(self);
+        make.height.mas_equalTo(0.5);
+    }];
 }
 
 - (void)btnClick:(UIButton *)btn
@@ -142,6 +150,7 @@ static const NSInteger btnTag = 20000;
         [_rightSendBtn setTitle:@"发送" forState:UIControlStateNormal];
         [_rightSendBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
         _rightSendBtn.hidden = YES;
+        _rightSendBtn.clipsToBounds = YES;
         _rightSendBtn.layer.cornerRadius = 4.0;
         _rightSendBtn.tag = btnTag + 2;
         [self.textBgView addSubview:_rightSendBtn];