|
@@ -41,18 +41,20 @@
|
|
|
#import "UIView+SDAutoLayout.h"
|
|
|
#import "LEETheme.h"
|
|
|
#import "GlobalDefines.h"
|
|
|
+#import "SLMoentsChatView.h"
|
|
|
|
|
|
#define kTimeLineTableViewCellId @"SDTimeLineCell"
|
|
|
|
|
|
-static CGFloat textFieldH = 40;
|
|
|
+static CGFloat textFieldH = 56;
|
|
|
|
|
|
-@interface SDTimeLineTableViewController () <SDTimeLineCellDelegate, UITextFieldDelegate>
|
|
|
+@interface SDTimeLineTableViewController () <SDTimeLineCellDelegate, UITextFieldDelegate, Delegates>
|
|
|
|
|
|
-@property (nonatomic, strong) UITextField *textField;
|
|
|
+@property (nonatomic, strong) UITextView *textField;
|
|
|
@property (nonatomic, assign) BOOL isReplayingComment;
|
|
|
@property (nonatomic, strong) NSIndexPath *currentEditingIndexthPath;
|
|
|
@property (nonatomic, copy) NSString *commentToUser;
|
|
|
|
|
|
+@property (nonatomic, strong) SLMoentsChatView *moentsChatView;
|
|
|
@end
|
|
|
|
|
|
@implementation SDTimeLineTableViewController
|
|
@@ -128,7 +130,7 @@ static CGFloat textFieldH = 40;
|
|
|
|
|
|
[self.tableView registerClass:[SDTimeLineCell class] forCellReuseIdentifier:kTimeLineTableViewCellId];
|
|
|
|
|
|
- [self setupTextField];
|
|
|
+
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
|
|
|
}
|
|
@@ -136,7 +138,7 @@ static CGFloat textFieldH = 40;
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
{
|
|
|
[super viewDidAppear:animated];
|
|
|
-
|
|
|
+ [self setupTextField];
|
|
|
if (!_refreshHeader.superview) {
|
|
|
|
|
|
_refreshHeader = [SDTimeLineRefreshHeader refreshHeaderWithCenter:CGPointMake(40, 45)];
|
|
@@ -163,6 +165,11 @@ static CGFloat textFieldH = 40;
|
|
|
[_textField resignFirstResponder];
|
|
|
}
|
|
|
|
|
|
+- (void)viewDidDisappear:(BOOL)animated {
|
|
|
+ [super viewDidDisappear:animated];
|
|
|
+ [_moentsChatView removeFromSuperview];
|
|
|
+}
|
|
|
+
|
|
|
- (void)dealloc
|
|
|
{
|
|
|
[_refreshHeader removeFromSuperview];
|
|
@@ -174,40 +181,41 @@ static CGFloat textFieldH = 40;
|
|
|
|
|
|
- (void)setupTextField
|
|
|
{
|
|
|
- _textField = [UITextField new];
|
|
|
- _textField.returnKeyType = UIReturnKeyDone;
|
|
|
- _textField.delegate = self;
|
|
|
- _textField.layer.borderColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.8].CGColor;
|
|
|
- _textField.layer.borderWidth = 1;
|
|
|
-
|
|
|
- //为textfield添加背景颜色 字体颜色的设置 还有block设置 , 在block中改变它的键盘样式 (当然背景颜色和字体颜色也可以直接在block中写)
|
|
|
+ self.moentsChatView = [[SLMoentsChatView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, self.view.width_sd, textFieldH)];
|
|
|
+ self.moentsChatView.backgroundColor = SLColor(@"#F5F5F5");
|
|
|
+ [[UIApplication sharedApplication].keyWindow addSubview:self.moentsChatView];
|
|
|
|
|
|
- _textField.lee_theme
|
|
|
- .LeeAddBackgroundColor(DAY , [UIColor whiteColor])
|
|
|
- .LeeAddBackgroundColor(NIGHT , [UIColor blackColor])
|
|
|
- .LeeAddTextColor(DAY , [UIColor blackColor])
|
|
|
- .LeeAddTextColor(NIGHT , [UIColor grayColor])
|
|
|
- .LeeAddCustomConfig(DAY , ^(UITextField *item){
|
|
|
+ _textField = self.moentsChatView.nextGrowingTextView.textView;
|
|
|
+ _textField.returnKeyType = UIReturnKeyDone;
|
|
|
+ self.moentsChatView.nextGrowingTextView.delegates = self;
|
|
|
+ WS(weakSelf);
|
|
|
+ self.moentsChatView.sendTextBlock = ^(NSString * _Nonnull text) {
|
|
|
+ [weakSelf.textField resignFirstResponder];
|
|
|
+ [weakSelf.view endEditing:YES];
|
|
|
+ SDTimeLineCellModel *model = weakSelf.dataArray[weakSelf.currentEditingIndexthPath.row];
|
|
|
+ NSMutableArray *temp = [NSMutableArray new];
|
|
|
+ [temp addObjectsFromArray:model.commentItemsArray];
|
|
|
+ SDTimeLineCellCommentItemModel *commentItemModel = [SDTimeLineCellCommentItemModel new];
|
|
|
|
|
|
- item.keyboardAppearance = UIKeyboardAppearanceDefault;
|
|
|
- if ([item isFirstResponder]) {
|
|
|
- [item resignFirstResponder];
|
|
|
- [item becomeFirstResponder];
|
|
|
+ if (weakSelf.isReplayingComment) {
|
|
|
+ commentItemModel.firstUserName = @"GSD_iOS";
|
|
|
+ commentItemModel.firstUserId = @"GSD_iOS";
|
|
|
+ commentItemModel.secondUserName = weakSelf.commentToUser;
|
|
|
+ commentItemModel.secondUserId = weakSelf.commentToUser;
|
|
|
+ commentItemModel.commentString = text;
|
|
|
+
|
|
|
+ weakSelf.isReplayingComment = NO;
|
|
|
+ } else {
|
|
|
+ commentItemModel.firstUserName = @"GSD_iOS";
|
|
|
+ commentItemModel.commentString = text;
|
|
|
+ commentItemModel.firstUserId = @"GSD_iOS";
|
|
|
}
|
|
|
- }).LeeAddCustomConfig(NIGHT , ^(UITextField *item){
|
|
|
+ [temp addObject:commentItemModel];
|
|
|
+ model.commentItemsArray = [temp copy];
|
|
|
+ [weakSelf.tableView reloadRowsAtIndexPaths:@[weakSelf.currentEditingIndexthPath] withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
|
|
- item.keyboardAppearance = UIKeyboardAppearanceDark;
|
|
|
- if ([item isFirstResponder]) {
|
|
|
- [item resignFirstResponder];
|
|
|
- [item becomeFirstResponder];
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- _textField.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, self.view.width_sd, textFieldH);
|
|
|
- [[UIApplication sharedApplication].keyWindow addSubview:_textField];
|
|
|
-
|
|
|
- [_textField becomeFirstResponder];
|
|
|
- [_textField resignFirstResponder];
|
|
|
+ weakSelf.textField.text = @"";
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
// 右栏目按钮点击事件
|
|
@@ -349,7 +357,7 @@ static CGFloat textFieldH = 40;
|
|
|
}];
|
|
|
|
|
|
[cell setDidClickCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow, NSIndexPath *indexPath) {
|
|
|
- weakSelf.textField.placeholder = [NSString stringWithFormat:@" 回复:%@", commentId];
|
|
|
+// weakSelf.textField.placeholder = [NSString stringWithFormat:@" 回复:%@", commentId];
|
|
|
weakSelf.currentEditingIndexthPath = indexPath;
|
|
|
[weakSelf.textField becomeFirstResponder];
|
|
|
weakSelf.isReplayingComment = YES;
|
|
@@ -385,7 +393,7 @@ static CGFloat textFieldH = 40;
|
|
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
|
|
{
|
|
|
[_textField resignFirstResponder];
|
|
|
- _textField.placeholder = nil;
|
|
|
+// _textField.placeholder = nil;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -466,59 +474,18 @@ static CGFloat textFieldH = 40;
|
|
|
[self.tableView setContentOffset:offset animated:YES];
|
|
|
}
|
|
|
|
|
|
-#pragma mark - UITextFieldDelegate
|
|
|
-
|
|
|
-- (BOOL)textFieldShouldReturn:(UITextField *)textField
|
|
|
-{
|
|
|
- if (textField.text.length) {
|
|
|
- [_textField resignFirstResponder];
|
|
|
-
|
|
|
- SDTimeLineCellModel *model = self.dataArray[_currentEditingIndexthPath.row];
|
|
|
- NSMutableArray *temp = [NSMutableArray new];
|
|
|
- [temp addObjectsFromArray:model.commentItemsArray];
|
|
|
- SDTimeLineCellCommentItemModel *commentItemModel = [SDTimeLineCellCommentItemModel new];
|
|
|
-
|
|
|
- if (self.isReplayingComment) {
|
|
|
- commentItemModel.firstUserName = @"GSD_iOS";
|
|
|
- commentItemModel.firstUserId = @"GSD_iOS";
|
|
|
- commentItemModel.secondUserName = self.commentToUser;
|
|
|
- commentItemModel.secondUserId = self.commentToUser;
|
|
|
- commentItemModel.commentString = textField.text;
|
|
|
-
|
|
|
- self.isReplayingComment = NO;
|
|
|
- } else {
|
|
|
- commentItemModel.firstUserName = @"GSD_iOS";
|
|
|
- commentItemModel.commentString = textField.text;
|
|
|
- commentItemModel.firstUserId = @"GSD_iOS";
|
|
|
- }
|
|
|
- [temp addObject:commentItemModel];
|
|
|
- model.commentItemsArray = [temp copy];
|
|
|
- [self.tableView reloadRowsAtIndexPaths:@[_currentEditingIndexthPath] withRowAnimation:UITableViewRowAnimationNone];
|
|
|
-
|
|
|
- _textField.text = @"";
|
|
|
- _textField.placeholder = nil;
|
|
|
-
|
|
|
- return YES;
|
|
|
- }
|
|
|
- return NO;
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- (void)keyboardNotification:(NSNotification *)notification
|
|
|
{
|
|
|
NSDictionary *dict = notification.userInfo;
|
|
|
CGRect rect = [dict[@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
CGRect textFieldRect = CGRectMake(0, rect.origin.y - textFieldH, rect.size.width, textFieldH);
|
|
|
if (rect.origin.y == [UIScreen mainScreen].bounds.size.height) {
|
|
|
textFieldRect = rect;
|
|
|
}
|
|
|
|
|
|
[UIView animateWithDuration:0.25 animations:^{
|
|
|
- _textField.frame = textFieldRect;
|
|
|
+ self.moentsChatView.frame = textFieldRect;
|
|
|
}];
|
|
|
|
|
|
CGFloat h = rect.size.height + textFieldH;
|
|
@@ -528,4 +495,24 @@ static CGFloat textFieldH = 40;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)willChangeHeight:(CGFloat)height
|
|
|
+{
|
|
|
+ [self bottomChangeHeight:height];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)didChangeHeight:(CGFloat)height
|
|
|
+{
|
|
|
+ [self bottomChangeHeight:height];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)bottomChangeHeight:(CGFloat)height
|
|
|
+{
|
|
|
+ CGRect rect = self.moentsChatView.frame;
|
|
|
+ CGFloat h = MAX(height + 16, 56);
|
|
|
+ rect.origin.y = rect.origin.y - (h - rect.size.height);
|
|
|
+ rect.size.height = h;
|
|
|
+ self.moentsChatView.frame = rect;
|
|
|
+ [self.moentsChatView setNeedsDisplay];
|
|
|
+}
|
|
|
+
|
|
|
@end
|