這不是一個優化的代碼,但你可以嘗試這樣的事情。
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return headerHeight;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat maxHeaderHeight = 400;
CGFloat minHeaderHeight = 40;
if (self.lastContentOffset > scrollView.contentOffset.y){
// scrolling down
if(headerHeight < maxHeaderHeight){
headerHeight += scrollView.contentOffset.y;
}
headerHeight = MIN(headerHeight, maxHeaderHeight);
}else if (self.lastContentOffset < scrollView.contentOffset.y){
// scrolling up
if (headerHeight > minHeaderHeight) {
headerHeight -= scrollView.contentOffset.y;
}
headerHeight = MAX(headerHeight, minHeaderHeight);
}
self.lastContentOffset = scrollView.contentOffset.y;
[self.tableView reloadData];
}
如果可能,你可以發佈一個顯示整個動畫的gif,很難確定使用圖像前後的方法!但很可能這種行爲可以通過使用具有適當動畫的「UITableViewCell」和「UIView」來複制,具體取決於用戶滾動的數量! – Rikh
顯示代碼,如何確定高度。 – iphonic
Spotify應用程序可能使用collectionview。 – Groot