iOS tableView中headView和footView悬停方式

简单的记录下今天遇到的一个比较感兴趣的问题,总共有四种

一: 2个都悬停 UITableViewStylePlain  //没什么好疑问的

二:2个都不悬停 UITableViewStyleGrouped //也没啥好疑问的

三:头部不悬停 底部悬停 使用UITableViewStylePlain(网上很多都是这样的)

-(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); 

        } 

    } 

}

四:头部悬停 底部不悬停

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

    }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容