您的位置:首页 > 产品设计 > UI/UE

iOS开发~UITableView区头跟随移动

2016-05-26 11:33 561 查看
UITableView想要区头跟随移动,可以设置style为UITableViewStyleGrouped,然而grouped有时候达不到想要的效果,就需要使用UITableViewStylePlain,在plain下想要区头跟随移动,需要添加以下代码:

//区头跟随移动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = 40;

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

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息