需求是可以上下你弦、左右滑動的效果馅精,我的方案是tableview+(tableview+scrollview)杂瘸,很簡單,如圖
藍(lán)色為手機屏幕碉咆,黃色為左側(cè)固定展示的tableview,橙色為scrollview嵌套tableview蛀恩,實現(xiàn)上下疫铜、左右滑動。通過scrollViewDidScroll
綁定兩個tableview的滾動双谆, - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
實現(xiàn)急停效果壳咕,聯(lián)合運用tracking
、dragging
顽馋、decelerating
等屬性實現(xiàn)體驗優(yōu)化谓厘,不作贅述。使用tableFooterView
屬性構(gòu)建tableview的腳視圖寸谜,實現(xiàn)點擊加載更多竟稳,左側(cè)tableview的腳視圖設(shè)置為屏寬,tableview.tableFooterView.clipsToBounds = NO
可實現(xiàn)腳視圖超越父視圖進(jìn)行展示(或?qū)⒆髠?cè)tableview的寬度設(shè)為屏寬)熊痴。右側(cè)橫滑tableview的腳視圖設(shè)置為其自身tableview寬度他爸,顏色透明,點擊事件和右側(cè)tableview執(zhí)行統(tǒng)一方法果善,統(tǒng)一reload诊笤。
然而,坑來了巾陕,reload之后向下拖動的時候視圖會出現(xiàn)抖動讨跟,二者偏移量會持續(xù)出現(xiàn)差值(16),即使設(shè)置統(tǒng)一的contentOffset
也無效鄙煤。
解決辦法:
if(@available(iOS11.0, *)) {
[UITableView appearance].estimatedRowHeight = 0;
[UITableView appearance].estimatedSectionFooterHeight = 0;
[UITableView appearance].estimatedSectionHeaderHeight = 0;
[UITableView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
放到didFinishLaunchingWithOptions
晾匠,OK!
有關(guān)tableview出現(xiàn)的任何毫無緣由的bug梯刚,嘗試適配一下iOS11很可能會有驚喜混聊,比如我。乾巧。句喜。