123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615 |
- //
- // SLMomentsVc.m
- // SLAiELTS
- //
- // Created by Gusont on 2023/4/14.
- //
- #import "SLMomentsVc.h"
- #import "SDTimeLineTableHeaderView.h"
- #import "SDTimeLineCell.h"
- #import "SDTimeLineCellModel.h"
- #import "UITableView+SDAutoTableViewCellHeight.h"
- #import "UIView+SDAutoLayout.h"
- #import "SLMoentsChatView.h"
- #import "SLMomentsCommentVc.h"
- #import "SLMomentDetailTableVc.h"
- #import "SLCreatMomentsVc.h"
- #define kTimeLineTableViewCellId @"SDTimeLineCell"
- static CGFloat textFieldH = 56;
- @interface SLMomentsVc () <SDTimeLineCellDelegate, UITextFieldDelegate, Delegates>
- @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;
- @property (nonatomic, strong) SDTimeLineCellCommentItemModel *currentCommentItemModel;
- @property (nonatomic, strong) NSString *currentCacheFriendId;
- @property (nonatomic, strong) SDTimeLineTableHeaderView *headerView;
- @end
- @implementation SLMomentsVc
- {
- CGFloat _lastScrollViewOffsetY;
- CGFloat _totalKeybordHeight;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- [self confignNavigationBar];
- if (@available(iOS 11.0, *)) {
- self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- if (!self.userModel) {
- self.userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
- }
- self.headerView = [[SDTimeLineTableHeaderView alloc] initWithFrame:CGRectMake(0, 0, 0, 220 * KScaleW)];
- self.tableView.tableHeaderView = self.headerView;
- self.tableView.tableHeaderView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 250 * KScaleW);
- //添加分隔线颜色设置
- self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
- [self.tableView registerClass:[SDTimeLineCell class] forCellReuseIdentifier:kTimeLineTableViewCellId];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardNotification:) name:UIKeyboardWillChangeFrameNotification object:nil];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(momentsUpdateType:) name:@"SLMomentsUpdateType" object:nil];
- [self creatModelsWithCount:0];
- if (!self.isDetail && !self.dataArray.count) {
- NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@--%@", self.userModel.userId,@(self.isFriendList)];
- NSString *cacheStr = [[NSUserDefaults standardUserDefaults] objectForKey:cacheKey];
- NSArray *items = [[cacheStr mj_JSONObject] objectForKey:@"items"];
- if (items.count) {
- NSArray<SDTimeLineCellModel *> *models = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
- self.currentCacheFriendId = models.firstObject.friendId;
- if (!self.dataArray.count) {
- [self.dataArray addObjectsFromArray:models];
- }
- }
- }
- if ([self.userModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId] && !self.isFriendList) {
- WS(weakSelf);
- [self.KVOController observe:[SLGlobalInfo SharedInstance] keyPath:@"loginInfo" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
- [weakSelf updateTableViewHeaderView:YES];
- }];
- }
- }
- - (void)confignNavigationBar {
- self.navigationBar.separatorHeight = 0.0f;
- if (!self.isFriendList) {
- self.navigationBar.leftBarButtonItem = nil;
- UIImage *creatImage =[UIImage imageNamed:@"icon_home_add"];
- YMBarButtonItem *rightBarItem =[[YMBarButtonItem alloc]initWithImage:creatImage style:YMBarButtonItemPlain target:self action:@selector(creatBtnClick)];
- rightBarItem.titleInsets = UIEdgeInsetsMake(0, 0, 0, 20);
- self.navigationBar.rightBarButtonItem = rightBarItem;
- self.navigationBar.backgroundColor = [UIColor clearColor];
- self.title = @"朋友圈";
- }else {
- UIImage *backImage =[UIImage imageNamed:@"icon_back_w"];
- YMBarButtonItem *backBarButtonItem =[[YMBarButtonItem alloc]initWithImage:backImage style:YMBarButtonItemPlain target:self action:@selector(backBarButtonPressed:)];
- backBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 5, 0, 0);
- self.navigationBar.leftBarButtonItem= backBarButtonItem;
- }
- }
- - (void)updateTableViewHeaderView:(BOOL)needReload {
- [self.headerView confignHeaderWith:self.userModel];
- SLUserModel *userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
- if ([self.userModel.userId isEqualToString:userModel.userId]) {
- self.userModel = userModel;
- [self.headerView updateHeaderViewWith:userModel.momentsMsgNotice];
- self.headerView.bgSelImageView.hidden = NO;
- if (self.isFriendList) {
- self.headerView.frame = CGRectMake(0, 0, 0, 220 * KScaleW);
- self.tableView.tableHeaderView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, 250 * KScaleW);
- }else {
- NSInteger unReadCount = [self.userModel.momentsMsgNotice integerValue];
- CGFloat h = unReadCount ? 70 : 0;
- self.headerView.frame = CGRectMake(0, 0, 0, (220 + h) * KScaleW);
- self.tableView.tableHeaderView.frame = CGRectMake(0, 0, kSCREEN_WIDTH, (250 + h) * KScaleW);
- self.rdv_tabBarItem.badgeValue = unReadCount < 99 ? [NSString stringWithFormat:@"%ld",unReadCount] : @"99+";
- self.rdv_tabBarItem.badgePositionAdjustment = UIOffsetMake(-10, 0);
- self.rdv_tabBarItem.badgeTextFont = [UIFont systemFontOfSize:10];
- if (needReload) {
- [self.tableView reloadData];
- }
- }
- }
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if ([self.userModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId]) {
- self.userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
- }
- if ([self.tableView.tableHeaderView isKindOfClass:SDTimeLineTableHeaderView.class]) {
- [self updateTableViewHeaderView:NO];
- }
- if (self.tableView.contentOffset.y < 300 && !self.tableView.mj_header.refreshing) {
- [self.tableView.mj_header beginRefreshing];
- }
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
- [self setupTextField];
- }
- - (void)viewWillDisappear:(BOOL)animated
- {
- [_textField resignFirstResponder];
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- [_moentsChatView removeFromSuperview];
- }
- - (void)dealloc
- {
- [_textField removeFromSuperview];
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)creatBtnClick {
- WS(weakSelf);
- [SLCustomizeAlert showBottomAletrWithTitles:@[@"拍照", @"从手机相册选择", @"纯文本"] cancelTitle:@"取消" buttonIndex:^(NSInteger index) {
- if (index != 3) {
- SLCreatMomentsVc *vc = [SLCreatMomentsVc loadViewControllewWithNib];
- vc.photoSelType = index;
- vc.creatMomentSuccess = ^{
- [weakSelf.tableView.mj_header beginRefreshing];
- };
- [weakSelf navPushViewController:vc animated:YES];
- }
- }];
- }
- - (void)momentsUpdateType:(NSNotification *)notification {
- NSDictionary *dict = notification.userInfo;
- SDTimeLineCellModel *model = [SDTimeLineCellModel mj_objectWithKeyValues:dict];
- __block NSInteger i = 0;
- __block SDTimeLineCellModel *cModel;
- [self.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj.friendId isEqualToString:model.friendId]) {
- i = idx;
- cModel = obj;
- *stop = YES;
- }
- }];
- if (cModel) {
- switch (cModel.updateType) {
- case SL_Detail:
- {
- SLMomentDetailTableVc *vc = [SLMomentsVc loadViewControllewWithNib];
- object_setClass(vc, SLMomentDetailTableVc.class);
- vc.isDetail = YES;
- vc.dataArray = [NSMutableArray arrayWithObject:cModel];
- [vc.tableView reloadData];
- [self navPushViewController:vc animated:YES];
- }
- break;
- case SL_CommentUpdate:
- {
- SLMomentsCommentVc *vc = [SLMomentsCommentVc loadViewControllewWithNib];
- WS(weakSelf);
- vc.momentsCommentBlock = ^(NSString * _Nonnull text) {
- [weakSelf updateCommentWithModel:cModel index:[NSIndexPath indexPathForRow:i inSection:0] text:text];
- };
- [self navPushViewController:vc animated:YES];
-
- }
- break;
- case SL_Update:
- {
- [self updateCellLike:cModel index:[NSIndexPath indexPathForRow:i inSection:0]];
- }
- break;
- default:
- break;
- }
-
- }
- }
- - (void)updateCommentWithModel:(SDTimeLineCellModel *)model index:(NSIndexPath *)index text:(NSString *)text {
- NSMutableArray *temp = [NSMutableArray new];
- [temp addObjectsFromArray:model.list];
- NSDictionary *parameter = @{@"commendId" : @"",
- @"friendId" : model.friendId,
- @"replyUserId" : @"",
- @"content" : text ?: @"",
- @"level" : @"0",
- };
- if (!self.isReplayingComment) {
- self.currentCommentItemModel = nil;
- }else {
- parameter = @{@"commendId" : self.currentCommentItemModel.commendId ?: @"",
- @"friendId" : self.currentCommentItemModel.friendId ?: @"",
- @"replyUserId" : self.currentCommentItemModel.userId ?: @"",
- @"content" : text ?: @"",
- @"level" : @"0",
- };
- self.isReplayingComment = NO;
- }
- [[SLHttpCenter SharedInstance] postWithUrl:@"/api/Friend/InsertComment" parameter:parameter success:^(id responseObject) {
- SDTimeLineCellCommentItemModel *commentItemModel = [SDTimeLineCellCommentItemModel new];
- SLLoginInfo *targetModel = [SLGlobalInfo SharedInstance].loginInfo;
- commentItemModel.userName = targetModel.user.userName;
- commentItemModel.userId = targetModel.user.userId;
- if (self.currentCommentItemModel) {
- commentItemModel.replyUserName = self.currentCommentItemModel.userName;
- }
- commentItemModel.content = text;
- commentItemModel.friendId = model.friendId;
- commentItemModel.level = [parameter objectForKey:@"level"];
- commentItemModel.commendId = [responseObject objectForKey:@"data"];
- [temp addObject:commentItemModel];
- model.list = [temp copy];
- [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
- } failure:^(SPRequestError *error) {
-
- }];
- }
- - (void)setupTextField
- {
- 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 = self.moentsChatView.nextGrowingTextView.textView;
- _textField.returnKeyType = UIReturnKeyDone;
- self.moentsChatView.nextGrowingTextView.delegates = self;
- WS(weakSelf);
-
- self.moentsChatView.sendTextBlock = ^(NSString * _Nonnull text) {
- if (!text.length) {
- return;
- }
- [weakSelf.textField resignFirstResponder];
- [weakSelf.view endEditing:YES];
- SDTimeLineCellModel *model = weakSelf.dataArray[weakSelf.currentEditingIndexthPath.row];
- [weakSelf updateCommentWithModel:model index:weakSelf.currentEditingIndexthPath text:text];
- weakSelf.textField.text = @"";
- };
- }
- - (void)creatModelsWithCount:(NSInteger)count
- {
- WS(weakSelf);
- [self.tableView tableviewRefresh:self.dataArray TableViewRefresh:^(NSInteger pageNo, TableListCount listCount) {
- NSDictionary *parameter = @{@"PageIndex": @(pageNo),
- @"PageSize": @(SLPageSize),
- @"type" : @"0",
- @"userId" : self.userModel.userId,
- };
- NSString *url = weakSelf.isFriendList ? @"/api/Friend/GetUserFriendList" : @"/api/Friend/GetFriendList";
-
- [[SLHttpCenter SharedInstance] getWithUrl:url parameter:parameter success:^(id responseObject) {
- NSDictionary *data = [responseObject objectForKey:@"data"];
- [SLGlobalInfo SharedInstance].loginInfo.user.momentsMsgNotice = [[data objectForKey:@"unread"] stringValue];
- [self updateTableViewHeaderView:NO];
- NSArray *items = [data objectForKey:@"items"];
- if (items.count) {
- NSMutableArray *marr = [SDTimeLineCellModel mj_objectArrayWithKeyValuesArray:items];
- [marr enumerateObjectsUsingBlock:^(SDTimeLineCellModel *obj, NSUInteger idx, BOOL * _Nonnull stop) {
-
- obj.likeItemsArray = [NSMutableArray new];
- [obj.likeStr enumerateObjectsUsingBlock:^(id _Nonnull obj1, NSUInteger idx1, BOOL * _Nonnull stop) {
- SDTimeLineCellLikeItemModel *model = [[SDTimeLineCellLikeItemModel alloc] init];
- model.userName = obj1;
- model.userId = @"1111";
- [obj.likeItemsArray addObject:model];
- }];
- }];
- [weakSelf.dataArray addObjectsFromArray:marr];
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadData];
- SDTimeLineCellModel *firstObj = weakSelf.dataArray.firstObject;
- if (pageNo == 1 && ![firstObj.friendId isEqualToString:weakSelf.currentCacheFriendId]) {
- weakSelf.currentCacheFriendId = firstObj.friendId;
- NSString *cacheKey = [NSString stringWithFormat:@"SLMomentsCache--%@--%@", weakSelf.userModel.userId,@(weakSelf.isFriendList)];
- [[NSUserDefaults standardUserDefaults] setObject:[data mj_JSONString] forKey:cacheKey];
- [[NSUserDefaults standardUserDefaults] synchronize];
- }
- });
- [weakSelf.dataArray enumerateObjectsUsingBlock:^(SDTimeLineCellModel * obj, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([obj.friendImgUrl componentsSeparatedByString:@","].count == 1) {
- [weakSelf.KVOController observe:obj keyPath:@"imageSize" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSKeyValueChangeKey,id> * _Nonnull change) {
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:idx inSection:0], nil] withRowAnimation:UITableViewRowAnimationAutomatic];
- });
- }];
- }
- }];
-
- }
- listCount([items count]);
- } failure:^(SPRequestError *error) {
- listCount(-1);
- }];
- }];
- }
- #pragma -mark scrollViewDelegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
- UIColor * color = [UIColor whiteColor];
- CGFloat offsetY = scrollView.contentOffset.y;
- CGFloat alpha = 1.0;
- if (offsetY >= 2) {
- alpha = MIN(1, 1 - ((2 + kNavBarHeight - offsetY) / kNavBarHeight));
- self.navigationBar.backgroundColor = [color colorWithAlphaComponent:alpha];
- self.navigationBar.rightBarButtonItemView.itemImageView.image = ImageName(@"icon_pyq_more_back");
- self.navigationBar.titleItemView.alpha = alpha;
- self.navigationBar.leftBarButtonItemView.itemImageView.image = ImageName(@"icon_back_b");
- } else {
- self.navigationBar.titleItemView.alpha = 0;
- self.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];
- self.navigationBar.rightBarButtonItemView.itemImageView.image = ImageName(@"icon_pyq_more");
- self.navigationBar.leftBarButtonItemView.itemImageView.image = ImageName(@"icon_back_w");
- }
- }
- #pragma mark - tableviewDelegate
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return self.dataArray.count;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- SDTimeLineCell *cell = [tableView dequeueReusableCellWithIdentifier:kTimeLineTableViewCellId];
- cell.indexPath = indexPath;
- SDTimeLineCellModel *model = self.dataArray[indexPath.row];
- cell.model = model;
- __weak typeof(self) weakSelf = self;
- if (!cell.moreButtonClickedBlock) {
- [cell setMoreButtonClickedBlock:^(NSIndexPath *indexPath) {
- SDTimeLineCellModel *model = weakSelf.dataArray[indexPath.row];
- model.isOpening = !model.isOpening;
- [weakSelf.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
- // [weakSelf.tableView reloadData];
- }];
- //评论
- [cell setDidClickCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow, NSIndexPath *indexPath1) {
- weakSelf.currentEditingIndexthPath = [NSIndexPath indexPathForRow:indexPath1.row inSection:0];
- SDTimeLineCellModel *editModel = weakSelf.dataArray[indexPath1.row];
- [weakSelf.textField becomeFirstResponder];
- weakSelf.isReplayingComment = YES;
- weakSelf.currentCommentItemModel = [editModel.list objectAtIndex:indexPath1.section];
- weakSelf.commentToUser = commentId;
- [weakSelf adjustTableViewToFitKeyboard];
- }];
- //长按删除评论
- [cell setDidLongTouchCommentLabelBlock:^(NSString *commentId, CGRect rectInWindow, NSIndexPath *indexPath1) {
- //indexPath1 row == table row Section == SDTimeLineCellCommentItemModel.list
- SDTimeLineCellModel *editModel = [weakSelf.dataArray objectAtIndex:indexPath1.row];
- if ([editModel.userId isEqualToString:[SLGlobalInfo SharedInstance].loginInfo.user.userId]) {
- NSMutableArray *temp = [NSMutableArray new];
- [temp addObjectsFromArray:editModel.list];
- SDTimeLineCellCommentItemModel *commentModel = [editModel.list objectAtIndex:indexPath1.section];
- [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/DelateComment" parameter:@{@"commentId":commentModel.commendId} success:^(id responseObject) {
- [temp removeObjectAtIndex:indexPath1.section];
- editModel.list = [temp copy];
- [weakSelf.tableView reloadData];
- } failure:^(SPRequestError *error) {
- }];
- }
- }];
- cell.delegate = self;
- }
- ////// 此步设置用于实现cell的frame缓存,可以让tableview滑动更加流畅 //////
- [cell useCellFrameCacheWithIndexPath:indexPath tableView:tableView];
- ///////////////////////////////////////////////////////////////////////
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- // >>>>>>>>>>>>>>>>>>>>> * cell自适应 * >>>>>>>>>>>>>>>>>>>>>>>>
- if (indexPath.row > self.dataArray.count - 1) {
- return 0.0f;
- }
- id model = self.dataArray[indexPath.row];
- return [self.tableView cellHeightForIndexPath:indexPath model:model keyPath:@"model" cellClass:[SDTimeLineCell class] contentViewWidth:[self cellContentViewWith]];
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- return 0.001f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
- return 0.001f;
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- {
- [_textField resignFirstResponder];
- }
- - (CGFloat)cellContentViewWith
- {
- CGFloat width = [UIScreen mainScreen].bounds.size.width;
-
- // 适配ios7横屏
- if ([UIApplication sharedApplication].statusBarOrientation != UIInterfaceOrientationPortrait && [[UIDevice currentDevice].systemVersion floatValue] < 8) {
- width = [UIScreen mainScreen].bounds.size.height;
- }
- return width;
- }
- #pragma mark - SDTimeLineCellDelegate
- - (void)didClickcCommentButtonInCell:(UITableViewCell *)cell
- {
- [_textField becomeFirstResponder];
- _currentEditingIndexthPath = [self.tableView indexPathForCell:cell];
- [self adjustTableViewToFitKeyboard];
-
- }
- - (void)didClickLikeButtonInCell:(UITableViewCell *)cell
- {
- NSIndexPath *index = [self.tableView indexPathForCell:cell];
- SDTimeLineCellModel *model = self.dataArray[index.row];
- model.updateType = SL_Update;
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SLMomentsUpdateType" object:nil userInfo:[model mj_JSONObject]];
- // [self updateCellLike:model index:index];
- }
- - (void)didClickDelButtonInCell:(UITableViewCell *)cell
- {
- [SLCustomizeAlert showAletrWithTitle:@"温馨提示" message:@"是否要删除当条朋友圈内容" sureBtnTitle:@"确定" cancelBtnTitle:@"取消" sureBtnAction:^{
- NSIndexPath *index = [self.tableView indexPathForCell:cell];
- SDTimeLineCellModel *model = self.dataArray[index.row];
- [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/DelateFriendCircle" parameter:@{@"id":model.friendId} success:^(id responseObject) {
- [self.dataArray removeObject:model];
- [self.tableView reloadData];
- } failure:^(SPRequestError *error) {
-
- }];
- } cancelBtnAction:^{
-
- }];
- }
- - (void)didClickTransInCell:(UITableViewCell *)cell {
- NSIndexPath *index = [self.tableView indexPathForCell:cell];
- [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationFade];
- }
- - (void)updateCellLike:(SDTimeLineCellModel *)model index:(NSIndexPath *)index {
- NSMutableArray *temp = [NSMutableArray arrayWithArray:model.likeItemsArray];
- if ([self isEqual:[UIViewController getCurrentShowVC]]) {
- [[SLHttpCenter SharedInstance] getWithUrl:@"/api/Friend/LikeHe" parameter:@{@"friendId":model.friendId} success:^(id responseObject) {
-
- } failure:^(SPRequestError *error) {
-
- }];
- }
- SLUserModel *userModel = [SLGlobalInfo SharedInstance].loginInfo.user;
- if (!model.isLike) {
- SDTimeLineCellLikeItemModel *likeModel = [SDTimeLineCellLikeItemModel new];
- likeModel.userName = userModel.userName;
- likeModel.userId = userModel.userId;
- [temp addObject:likeModel];
- model.isLike = YES;
- } else {
- SDTimeLineCellLikeItemModel *tempLikeModel = nil;
- for (SDTimeLineCellLikeItemModel *likeModel in model.likeItemsArray) {
- if ([likeModel.userName isEqualToString:userModel.userName]) {
- tempLikeModel = likeModel;
- break;
- }
- }
- [temp removeObject:tempLikeModel];
- model.isLike = NO;
- }
- model.likeItemsArray = [temp copy];
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [self.tableView reloadRowsAtIndexPaths:@[index] withRowAnimation:UITableViewRowAnimationNone];
- });
- }
- #pragma mark - Keyboard
- - (void)adjustTableViewToFitKeyboard
- {
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:_currentEditingIndexthPath];
- CGRect rect = [cell.superview convertRect:cell.frame toView:window];
- [self adjustTableViewToFitKeyboardWithRect:rect];
- }
- - (void)adjustTableViewToFitKeyboardWithRect:(CGRect)rect
- {
- UIWindow *window = [UIApplication sharedApplication].keyWindow;
- CGFloat delta = CGRectGetMaxY(rect) - (window.bounds.size.height - _totalKeybordHeight);
-
- CGPoint offset = self.tableView.contentOffset;
- offset.y += delta;
- if (offset.y < 0) {
- offset.y = 0;
- }
-
- [self.tableView setContentOffset:offset animated:YES];
- }
- - (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:^{
- self.moentsChatView.frame = textFieldRect;
- }];
- CGFloat h = rect.size.height + textFieldH;
- if (_totalKeybordHeight != h) {
- _totalKeybordHeight = h;
- [self adjustTableViewToFitKeyboard];
- }
- }
- - (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];
- }
- - (NSMutableArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- @end
|