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

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

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

2019-11-09 14:18:55
字體:
供稿:網(wǎng)友

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

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

先放上效果圖:

這里寫圖片描述

主要邏輯代碼:

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ā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 南岸区| 辽中县| 高雄县| 大厂| 哈尔滨市| 都昌县| 东阿县| 漾濞| 康马县| 台前县| 伊宁市| 建阳市| 名山县| 潞城市| 伊金霍洛旗| 天台县| 云霄县| 恭城| 林周县| 青川县| 福建省| 北京市| 昭平县| 手游| 吉林市| 渭南市| 宁海县| 平江县| 水富县| 搜索| 策勒县| 贡山| 河津市| 西林县| 德兴市| 土默特左旗| 镇平县| 克什克腾旗| 游戏| 当阳市| 吴川市|