[10秒学会] - iOS tableView中headView和footView悬停方式

效果图头部悬停 底部不悬停
spa

一共4种code

一: 2个都悬停 UITableViewStylePlain  //没什么好疑问的
二:2个都不悬停 UITableViewStyleGrouped //也没啥好疑问的
三:头部不悬停 底部悬停 使用UITableViewStylePlain //网上已经不少这个代码 仍是贴一下吧io

-(void)scrollViewDidScroll:(UIScrollView *)scrollView {  
//    if (scrollView == self.myTableView)  
    {  
        //YOUR_HEIGHT 为最高的那个headerView的高度  
//        CGFloat sectionHeaderHeight = 20;  
        if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {  
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);  
        } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {  
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);  
        }  
    }  
}

四 才是今天咱们的重点 头部悬停 底部不悬停
 table

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0); //首先改变内边距 -105是底部的距离
    CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:2]]; //如今是写死的 你能够根据模型数据 写成变量
    CGRect rect = [self.tableView convertRect:rectInTableView toView:[self.tableView superview]];//这是是最后cell row的高度
    if(rect.origin.y<=-1288){ //-1288  这个位置 是能够根据你的位置调整出来
        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    }else{
        self.tableView.contentInset = UIEdgeInsetsMake(0, 0, -105, 0);
    }
相关文章
相关标签/搜索