一,关于键盘弹起
- 判断点击所在的cell在屏幕上的位置是否被键盘遮挡
cell所在位置可以通过以下两种方法获取
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
//tableview 偏移量
_currentSrollowHeight=self.tvContent.contentOffset.y;
NSLog(@"textFieldShouldBeginEditing---%f---:%f",_tvContent.contentOffset.y,_currentSrollowHeight);
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:textView.tag%100 inSection:textView.tag/100];
CGRect rectInTableView = [self.tvContent rectForRowAtIndexPath:indexPath];
CGRect rectInSuperView = [self.tvContent convertRect:rectInTableView toView:self.view];
//点击cell位置
_currentSelectTextfieldLocation = rectInSuperView.origin.y;
//索引
_selectTextfiedIndex=textView.tag;
return YES;
}
- (void)keyboardWillShow:(NSNotification *)notification
{
NSDictionary *userInfo = notification.userInfo;
CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
// 取得键盘的动画时间,这样可以在视图上移的时候更连贯
CGFloat offset;
CGFloat theHeight;
// _theRowHeighth cell高度
theHeight=_currentSelectTextfieldLocation+_theRowHeight;
offset=theHeight-(SCREEN_HEIGHT-endFrame.size.height);
NSLog(@"endFrame.size.height---%f---%f---%f",endFrame.size.height,theHeight,offset);
//将视图上移计算好的偏移
if(offset > 0)
{
[self.tvContent setContentOffset:CGPointMake(0, offset+_currentSrollowHeight) animated:YES];
}
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSLog(@"_currentSrollowHeight---%f",_currentSrollowHeight);
[self.tvContent setContentOffset:CGPointMake(0, _currentSrollowHeight) animated:YES];
}
键盘高度在通知方法里可以获取
网友评论