iOS UITableView上滑吸顶的三种方案

iOS 中很多时候回碰到上滑吸顶的效果,现在总结了以下三种方案,个人比较推崇第一种

1、 UITableViewStylePlain样式下tableHeaderView和sectionHeader共用。tableHeaderView设置为顶部滚动元素,需要第几组的heder吸顶就直接设置sectionHeader

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 10;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
    
}

2、设置 UITableView顶部内间距, 将吸顶元素添加在view上 ,滚动过程中变化吸顶元素y值。

3、吸顶元素添加在view上, UITableView顶部和吸顶元素底部相同 ,   滚动过程中变化吸顶元素y值 。 效果不好(因为顶部元素和table高度都在变)

原文地址:https://www.cnblogs.com/lijianyi/p/11492705.html