iOS 之 列表联动
2017-02-10 09:25
393 查看
左侧是tableview,右侧是collectionView
其实原理很简单:就是左侧放一个tableview,右侧放一个collectionView(也可以是tableview),只要搞清楚点击表,或者滑动collection的时候,另一个做出相应的效果来就好了先放上效果图:
主要逻辑代码:
1.首先是点击tableview的时候,要计算出collectionView要滚动到的位置:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 计算出 右侧 collectionView 将要 滚动的 位置 NSIndexPath *moveToIndexPath = [NSIndexPath indexPathForRow:0 inSection:indexPath.row]; [self.collectionView selectItemAtIndexPath:moveToIndexPath animated:YES scrollPosition:UICollectionViewScrollPositionTop]; }
2.然后是滑动collectionView的时候,计算tableview要响应的位置:
- (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地址
相关文章推荐
- ios 即时聊天轻松搞定
- iOS使用imageIO完成渐进加载图片
- 『可变』的热信号 RACSubject
- iOS随机产生两数之间的浮点数
- iOS开源项目周报0209
- IOS学习之block代码块
- Navigation bar 的注意事项
- IOS 学习之一基础
- (六)CocoaPods 常见问题(原文翻译)
- iOS基础知识点温习
- iOS开发之OC篇(4)—— NSDictionary、NSMutableDictionary
- iOS开发之OC篇(3)—— NSArray、NSMutableArray
- iOS开发之OC篇(2)——NSString、NSMutableString
- Orientation - 3
- iOS开发断点调试高级技巧
- DLNA_iOS_Platinum
- iOS 字典按照key的排序
- iOS-清除缓存
- IOS 使用cocoapods后无法导入头文件问题
- iOS中使用blend改变图片颜色