国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 莱阳市| 依安县| 红安县| 宣汉县| 磐安县| 长宁区| 获嘉县| 和顺县| 喀喇| 汝南县| 泸水县| 苏尼特左旗| 宜州市| 泾川县| 萨嘎县| 临汾市| 达拉特旗| 湛江市| 荆门市| 虹口区| 麦盖提县| 和硕县| 敦煌市| 万全县| 华蓥市| 临邑县| 滦南县| 邵东县| 九寨沟县| 濮阳市| 莲花县| 武功县| 溧阳市| 伽师县| 象州县| 长春市| 广河县| 吴江市| 罗源县| 梅河口市| 内丘县|