iOS UITableView4

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];

    }];

}];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值