国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 系統(tǒng) > iOS > 正文

iOS 之 列表聯(lián)動(dòng)

2019-11-09 15:23:25
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

左側(cè)是tableview,右側(cè)是collectionView

其實(shí)原理很簡(jiǎn)單:就是左側(cè)放一個(gè)tableview,右側(cè)放一個(gè)collectionView(也可以是tableview),只要搞清楚點(diǎn)擊表,或者滑動(dòng)collection的時(shí)候,另一個(gè)做出相應(yīng)的效果來(lái)就好了

先放上效果圖:

這里寫圖片描述

主要邏輯代碼:

1.首先是點(diǎn)擊tableview的時(shí)候,要計(jì)算出collectionView要滾動(dòng)到的位置:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 計(jì)算出 右側(cè) collectionView 將要 滾動(dòng)的 位置 NSIndexPath *moveToIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row]; [self.collectionView selectItemAtIndexPath:moveToIndexPath animated:YES scrollPosition:UICollectionViewScrollPositionTop];}

2.然后是滑動(dòng)collectionView的時(shí)候,計(jì)算tableview要響應(yīng)的位置:

- (void)collectionView:(UICollectionView *)collectionView willDisplaySupplementaryView:(UICollectionReusableView *)view forElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath { if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) { if (indexPath.section!=0) { NSIndexPath *tabIndexPath = [NSIndexPath indexPathForRow:indexPath.section - 1 inSection:0]; [self.tableView selectRowAtIndexPath:tabIndexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; } }}

Demo地址


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 金寨县| 七台河市| 玛纳斯县| 无棣县| 长垣县| 上蔡县| 永新县| 都昌县| 阿克苏市| 盐山县| 红原县| 康保县| 汪清县| 鹤峰县| 清涧县| 玛纳斯县| 隆昌县| 常州市| 咸阳市| 庆安县| 威信县| 东港市| 隆子县| 内乡县| 无极县| 京山县| 库伦旗| 确山县| 肇庆市| 梧州市| 屏山县| 连山| 乌鲁木齐县| 富平县| 宜丰县| 芒康县| 崇礼县| 扎兰屯市| 章丘市| 龙口市| 临夏县|