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高度都在變)