首先判断点击评论按钮事件 和 回复评论事件(同时注册监听键盘出现和隐藏事件)
然后 获取到 所点击cell的坐标
然后 在键盘出来的时候计算所需要调整的高度
- (void)viewDidLoad {
[superviewDidLoad];
//注册键盘出现NSNotification
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotificationobject:nil];
//注册键盘隐藏NSNotification
[[NSNotificationCenterdefaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotificationobject:nil];
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"top_bg"]forBarMetrics:UIBarMetricsDefault];
// [self.navigationController.navigationBar setClipsToBounds:YES];
[selfloadData];
[selfcreateRightBtn];
//添加观察状态更新通知
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(refeshViewRequest:)name:@"FreshView"object:nil];
_replyIndex = -1;//代表是直接评论
_down =NO;
self.view.backgroundColor = [UIColorwhiteColor];
// Do any additional setup after loading the view.
//利用tableview缓存数据机制中的一个特别处理方式,如果缓存中没有则调用相关创建
// [self.tableView registerClass:[FriendsCell class] forCellReuseIdentifier:[FriendsCell ID]];
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(creatImgView)name:@"shequImg"object:nil];
self.tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0, IPHONE_WIDTH,IPHONE_HEIGHT - 64 -49 )];
//UITableview添加点击事件
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapGesturedDetected:)];
tapGesture.delegate =self;
[self.tableViewaddGestureRecognizer:tapGesture];
[self.tableViewregisterClass:[YMTableViewCellclass] forCellReuseIdentifier:@"ILTableViewCell"];
//添加朋友圈背景图片
CGFloat img_H =IPHONE_WIDTH * 3 /4;
// CGFloat img_H = IPHONE_WIDTH;
CGFloat WH = img_H +25;
UIView *headerView = [[UIViewalloc]initWithFrame:CGRectMake(0,0, IPHONE_WIDTH, WH)];
_bgImgView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, IPHONE_WIDTH, img_H)];
_bgImgView.contentMode =UIViewContentModeScaleAspectFill;
_bgImgView.clipsToBounds =YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(changeBgImgView)];
_bgImgView.userInteractionEnabled =YES;
[_bgImgViewaddGestureRecognizer:tap];
[headerView addSubview:_bgImgView];
_iconImgViw = [[UIImageViewalloc]initWithFrame:CGRectMake(IPHONE_WIDTH - 90, WH-70,70, 70)];
// //圆角
_iconImgViw.layer.cornerRadius =5.0f;
_iconImgViw.layer.borderWidth =1.0f;
_iconImgViw.layer.borderColor = [UIColorwhiteColor].CGColor;
_iconImgViw.layer.masksToBounds =YES;
_nameLab = [[UILabelalloc]initWithFrame:CGRectMake(IPHONE_WIDTH - 300, WH - 60,200, 30)];
_nameLab.textAlignment =NSTextAlignmentRight;
_nameLab.textColor = [UIColorwhiteColor];
self.tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
[selfcreatImgView];
[headerView addSubview:_nameLab];
[headerView addSubview:_iconImgViw];
self.tableView.tableHeaderView = headerView;
self.tableView.delegate =self;
self.tableView.dataSource =self;
// 刷新
self.headerView = [[MJRefreshHeaderViewalloc]initWithScrollView:_tableView];
self.footerView = [[MJRefreshFooterViewalloc]initWithScrollView:_tableView];
self.headerView.delegate =self;
self.footerView.delegate =self;
//点击按钮
self.clickBtn = [UIButtonbuttonWithType:UIButtonTypeCustom];
[self.viewaddSubview:self.tableView];
zlActionSheet = [[ZLPhotoActionSheetalloc] init];
//设置照片最大选择数
zlActionSheet.maxSelectCount =9;
//设置照片最大预览数
zlActionSheet.maxPreviewCount =20;
//观察相册选择确认
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(PhotoSureClick)name:@"hidePhtoAction"object:nil];
}
-(void)dealloc{
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"FreshView"object:nil];
[self.headerViewfree];
[self.footerViewfree];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"shequImg"object:nil];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:@"hidePhtoAction"object:nil];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardWillShowNotificationobject:nil];
[[NSNotificationCenterdefaultCenter]removeObserver:selfname:UIKeyboardWillHideNotificationobject:nil];
}
//cell的坐标
@property (nonatomic,assign)CGRect rectSelected;
#pragma mark - 按钮动画
- (void)replyAction:(YMButton *)sender{
//获取 cell的坐标
CGRect rectInTableView = [self.tableViewrectForRowAtIndexPath:sender.appendIndexPath];
CGFloat origin_Y = rectInTableView.origin.y + sender.frame.origin.y;
CGRect targetRect =CGRectMake(CGRectGetMinX(sender.frame), origin_Y,CGRectGetWidth(sender.bounds),CGRectGetHeight(sender.bounds));
DSLog(@" row --------- %ld",(long)sender.appendIndexPath.row);
self.rectSelected = [self.tableViewconvertRect:rectInTableViewtoView:[self.tableViewsuperview]];
// LFTableViewCell*cell = (LFTableViewCell*)[selftableView:tableViewcellForRowAtIndexPath:indexPath];
//
// return cell.frame.size.height;
// YMTableViewCell *cell = (YMTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// NSIndexPath *index1 = [NSIndexPath indexPathForItem:row inSection:0];
YMTableViewCell * cell1 = (YMTableViewCell * )[selftableView:_tableViewcellForRowAtIndexPath:sender.appendIndexPath];
CGFloat cell_H = cell1.frame.size.height;
// self.rectSelected.origin.y = self.rectSelected.origin.y + cell_H;
DSLog(@"cell_H : %f",cell_H);
DSLog(@" x %f y %f W %f H %f",self.rectSelected.origin.x,self.rectSelected.origin.y,self.rectSelected.size.width,self.rectSelected.size.height);
if (self.operationView.shouldShowed) {
// [self.operationView dismiss];
[self.operationViewdismissClick];
_selectedIndexPath = sender.appendIndexPath;
YMTextData *ym = [_tableDataSourceobjectAtIndex:_selectedIndexPath.row];
dramicID = ym.messageBody.dynamicId;
[self.operationViewshowAtView:self.tableViewrect:targetRectisFavour:ym.messageBody.isFavour];
return;//按钮展开就先消失,再次点击展开。
}
_selectedIndexPath = sender.appendIndexPath;
YMTextData *ym = [_tableDataSourceobjectAtIndex:_selectedIndexPath.row];
dramicID = ym.messageBody.dynamicId;
[self.operationViewshowAtView:self.tableViewrect:targetRectisFavour:ym.messageBody.isFavour];
}
#pragma mark - 点评论整块区域的回调
- (void)clickRichText:(NSInteger)index replyIndex:(NSInteger)replyIndex{
[self.operationViewdismiss];
if (replyIndex == -1) {
DSLog(@"点击说说的 停止执行");
return;
}
NSLog(@"点评论整块区域的回调");
_replyIndex = replyIndex;
YMTextData *ymData = (YMTextData *)[_tableDataSourceobjectAtIndex:index];
CommentListModel *b = [ymData.messageBody.posterRepliesobjectAtIndex:replyIndex];
if ([b.memberIdisEqualToString:[UserModelsharedInstance].memberId]) {
WFActionSheet *wfActionSheet = [[WFActionSheetalloc] initWithTitle:@"删除评论?"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:@"确定"otherButtonTitles:nil,nil];
wfActionSheet.actionIndex = index;
[wfActionSheet showInView:self.view];
}else{
//回复
NSLog(@"回复别人");
if (replyView) {
return;
}
if (replyView ==nil) {
//获取 cell的坐标
NSIndexPath * indexPath2 = [NSIndexPathindexPathForItem:index inSection:0];
CGRect rectInTableView = [self.tableViewrectForRowAtIndexPath:indexPath2];
self.rectSelected = [self.tableViewconvertRect:rectInTableViewtoView:[self.tableViewsuperview]];
replyView = [[YMReplyInputViewalloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 44, screenWidth,44)andAboveView:self.view];
[self.viewaddSubview:replyView];
}
replyView.delegate =self;
replyView.lblPlaceholder.text = [NSStringstringWithFormat:@"回复%@:",b.memberNick];
replyView.replyTag = index;
//
// dispatch_once(&emojiCreateOnce, ^{
// _emojiView = [CustomEmojiView shardInstance];
// _emojiView.delegate = self;
// _emojiView.frame = CGRectMake(0, self.view.frame.size.height, IPHONE_WIDTH, 216.0f);
//
// if (_emojiView.superview == nil) {
// [self.view addSubview:_emojiView];
// }
// });
if (_emojiView ==nil) {
_emojiView = [CustomEmojiViewshardInstance];
_emojiView.delegate =self;
_emojiView.frame =CGRectMake(0,self.view.frame.size.height,IPHONE_WIDTH, 216.0f);
[self.viewaddSubview:_emojiView];
}
}
UIViewController * cvc = [[UIViewControlleralloc] init];
cvc.view.tag =0;
NSDictionary *dict = [[NSDictionaryalloc]initWithObjectsAndKeys:cvc,@"Hidden",nil] ;
NSNotification *notification = [NSNotificationnotificationWithName:@"tongzhiHidden"object:niluserInfo:dict];
[[NSNotificationCenterdefaultCenter]postNotification:notification];
[self.tabBarController.viewsetFrame:CGRectMake(0,0, IPHONE_WIDTH,IPHONE_HEIGHT+60)];
}