Browse Source

消息界面优化

桂欢 1 năm trước cách đây
mục cha
commit
326ffa905c

+ 42 - 27
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/SLMessageViewController.m

@@ -31,6 +31,7 @@
     YMBarButtonItem *rightBarItem =[[YMBarButtonItem alloc]initWithImage:creatImage style:YMBarButtonItemPlain target:self action:@selector(moreBtnClick)];
     rightBarItem.titleInsets = UIEdgeInsetsMake(0, 0, 0, 20);
     self.navigationBar.rightBarButtonItem = rightBarItem;
+    [self.view bringSubviewToFront:self.navigationBar];
 }
 
 - (void)moreBtnClick {
@@ -44,43 +45,34 @@
     // Do any additional setup after loading the view from its nib.
     self.title = self.friendModel.userName;
     [self configNavigationBar];
-    NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
-    NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:key];
-    if (arr) {
-        NSArray *models = [MessageModel mj_objectArrayWithKeyValuesArray:arr];
-        self.chatServiceView.messageView.chatDataManager = [NSMutableArray arrayWithArray:models];
-    }
+    dispatch_async(dispatch_queue_create("sl.cache.chat.date", DISPATCH_QUEUE_CONCURRENT), ^{
+        NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
+        NSArray *arr = [[NSUserDefaults standardUserDefaults] objectForKey:key];
+        if (arr.count) {
+            dispatch_async(dispatch_get_main_queue(), ^{
+                NSArray *models = [MessageModel mj_objectArrayWithKeyValuesArray:arr];
+                self.chatServiceView.messageView.chatDataManager = [NSMutableArray arrayWithArray:models];
+                [self.chatServiceView.messageView.messageCollectionView reloadData];
+            });
+        }
+    });
+    
     self.chatServiceView.friendModel = self.friendModel;
     self.chatServiceView.messageView.friendModel = self.friendModel;
     [self.chatServiceView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.mas_equalTo(kNavBarHeight);
         make.left.bottom.right.equalTo(self.view);
     }];
-    self.mikeInputView = [[SLMikeInputView alloc] initWithFrame:CGRectZero];
-    WS(weakSelf);
-    self.mikeInputView.nuiSpeechRecognizer.recognizerResultBlock = ^(NSString * _Nonnull text, NSString * _Nonnull voicePath) {
-        MessageModel *model = [MessageModel initWithSendText:text isReceive:NO showMike:YES showText:NO isMike:YES voicePath:voicePath];
-        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-            if (model.audioDuration < 1.2) {
-                [ZFToast ShowWithMessage:@"说话时间太短!"];
-            }else {
-                model.toId = weakSelf.friendModel.userId;
-                [weakSelf.chatServiceView.messageView appendMessage:model];
-            }
-        });
-    };
-    self.mikeInputView.hidden = YES;
-    [self.view addSubview:self.mikeInputView];
-    [self.view bringSubviewToFront:self.navigationBar];
-    [self.view bringSubviewToFront:self.mikeInputView];
 
-    [self nuisdkPlay];
+    
+    WS(weakSelf);
+//    [self nuisdkPlay];
     [self.KVOController observe:self.mikeInputView.contentView keyPath:@"hidden" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id  _Nullable observer, id  _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
         if (![change[NSKeyValueChangeNewKey] boolValue]) {
             [weakSelf.nuisdkPlay stopNuisdkPlay];
         }
     }];
-    //
+//
     self.chatServiceView.messageView.broadcastBlock = ^(MessageModel * _Nonnull msgModel) {
         if (!msgModel.isReceive && msgModel.showMike) {
             [weakSelf.nuisdkPlay playSendVoice:msgModel];
@@ -113,8 +105,10 @@
 - (void)saveChatData {
     NSString *key = [NSString stringWithFormat:@"%@--to--%@",[SLGlobalInfo SharedInstance].loginInfo.user.userId, self.friendModel.userId];
     NSArray *dictArr = [NSObject mj_keyValuesArrayWithObjectArray:self.chatServiceView.messageView.chatDataManager];
-    [[NSUserDefaults standardUserDefaults] setObject:dictArr forKey:key];
-    [[NSUserDefaults standardUserDefaults] synchronize];
+    dispatch_async(dispatch_queue_create("sl.save.chat.date", DISPATCH_QUEUE_CONCURRENT), ^{
+        [[NSUserDefaults standardUserDefaults] setObject:dictArr forKey:key];
+        [[NSUserDefaults standardUserDefaults] synchronize];
+    });
 }
 
 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
@@ -203,6 +197,27 @@
     return _nuisdkPlay;
 }
 
+- (SLMikeInputView *)mikeInputView {
+    if (!_mikeInputView) {
+        _mikeInputView = [[SLMikeInputView alloc] initWithFrame:CGRectZero];
+        WS(weakSelf);
+        _mikeInputView.nuiSpeechRecognizer.recognizerResultBlock = ^(NSString * _Nonnull text, NSString * _Nonnull voicePath) {
+            MessageModel *model = [MessageModel initWithSendText:text isReceive:NO showMike:YES showText:NO isMike:YES voicePath:voicePath];
+            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+                if (model.audioDuration < 1.2) {
+                    [ZFToast ShowWithMessage:@"说话时间太短!"];
+                }else {
+                    model.toId = weakSelf.friendModel.userId;
+                    [weakSelf.chatServiceView.messageView appendMessage:model];
+                }
+            });
+        };
+        [self.view addSubview:_mikeInputView];
+        [self.view bringSubviewToFront:self.mikeInputView];
+    }
+    return _mikeInputView;
+}
+
 - (IBAction)backBtnClick:(id)sender {
     [self.navigationController popToRootViewControllerAnimated:YES];
 }

+ 3 - 4
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/Views/YMChatBottomView.m

@@ -69,9 +69,8 @@ static const NSInteger btnTag = 20000;
         make.top.greaterThanOrEqualTo(self.textBgView).offset(0).priority(1000);
         make.right.equalTo(self.rightSendBtn.mas_left).offset(-8);
     }];
-    [self btnClick:self.leftBtn];//
-    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-        [self btnClick:self.leftBtn];
+    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+        [self changeChatType:self.leftBtn];
     });
     
     UIView *lineView = [[UIView alloc] initWithFrame:CGRectZero];
@@ -166,7 +165,7 @@ static const NSInteger btnTag = 20000;
         _nextGrowingTextView.placeholderAttributedText = [[NSAttributedString alloc] initWithString:@" " attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 16], NSForegroundColorAttributeName : SLColor(@"#999999")}];
         _nextGrowingTextView.layer.cornerRadius = 4.0;
         _nextGrowingTextView.maxNumberOfLines = 6;
-        _nextGrowingTextView.hidden = YES;
+//        _nextGrowingTextView.hidden = YES;
         _nextGrowingTextView.textView.keyboardType = UIKeyboardTypeASCIICapable;
         [self.textBgView addSubview:_nextGrowingTextView];
     }

+ 0 - 13
SLAiELTS/SLAiELTS/ViewControllers/MessageVC/Views/YMChatServiceView.m

@@ -66,19 +66,6 @@
 
 }
 
-- (void)onVolumeChangedEx:(int)volume
-{
-    if (0 == volume) {
-//        self.chatBottomView.imBtnAnimateBg.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0];
-    }else {
-        CGFloat f = (volume + (arc4random() % 5)) / 100.0;
-         f = f * 0.5;
-        CGFloat s = f + 0.1;
-//        self.chatBottomView.imBtnAnimateBg.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:MAX((0.6 - s) * 0.7, 0.2)];
-//        self.chatBottomView.imBtnAnimateBg.transform = CGAffineTransformMakeScale(1 + s, 1 + s);
-    }
-}
-
 #pragma mark - changeHeight
 - (void)willChangeHeight:(CGFloat)height
 {