1获取坐标位置
pragma -mark 头视图拉伸放大
(void)scrollViewDidScroll:(UIScrollView *)scrollView{
float y = scrollView.contentOffset.y;
if(y < 0){
y = -y; float scale = (150+y)/150;
_headerImageView.transform = CGAffineTransformMakeScale(scale, scale);
_headerImageView.frame = CGRectMake(-(scale-1)/2*WidthOfScreen, -y, WidthOfScreen*scale, 150*scale);
}
}
=========collection
- (void)scrollViewWillEndDragging:(UIScrollView )scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint )targetContentOffset{
float y = targetContentOffset->y;
NSLog(@"22%f",y);
}
2String的长度 决定Label高度 决定cell的高度
pragma -mark cell的点击事件
(void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath{
_currentIndexPath = indexPath;
isSelect[indexPath.row] = !isSelect[indexPath.row];
[_commentTable reloadData];
}
pragma -mark rowHeigh 的设置方法
(CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{
if(_currentIndexPath == indexPath && isSelect[indexPath.row] == YES){
//根据string的长度计算label的高度 CommentModel *model = _modelArray[indexPath.row]; NSString *string = model.summary; CGRect frame = [string boundingRectWithSize:CGSizeMake(269, HUGE_VALF) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil]; return frame.size.height+ 120-44; =-= cell的高度 有影响
}
return 120;
}
3滑动到指定位置 选中的cell
NSIndexPath *path = [NSIndexPath indexPathForRow:_number-1 inSection:0];
//滑动到指定row
[_lineTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionBottom animated:YES];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
4键盘操作 完整版
//键盘弹出的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardShow:) name:UIKeyboardWillShowNotification object:nil];
//收起键盘
-(void)hideKeyBoard
{
[self.view endEditing:YES];
}
//键盘将要显示
-(void)keyboardShow:(NSNotification *)note
{
//获取用户信息
NSDictionary *userInfo = [note userInfo];
//获取键盘的size
CGSize size = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
//获取键盘弹出的动画时间
NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:duration.doubleValue animations:^{
//底部视图向上移动
_bottomView.transform = CGAffineTransformMakeTranslation(0, -size.height);
_tableView.transform = CGAffineTransformMakeTranslation(0, -size.height);
//滑动到底部
[self scrollToBottom];
}];
}
//键盘收回
[[NSNotificationCenter defaultCenter] addObserverForName:UIKeyboardWillHideNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
//获取用户信息
NSDictionary *userInfo = [note userInfo];
// CGSize size = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
NSNumber *duration = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
[UIView animateWithDuration:duration.doubleValue animations:^{
//还原
_bottomView.transform = CGAffineTransformIdentity;
_tableView.transform = CGAffineTransformIdentity;
//滑动到底部
[self scrollToBottom];
}];
}];