ios - 将视图控制器的视图添加到集合视图的底部以滚动?
问题描述
我有一个包含两个视图控制器的视图。第一个视图控制器包含一个集合视图(蓝色),其框架占据了整个视图。在这个 collectionview 中有许多滚动的对象(红色方块)。我想将第二个 viewcontroller 的视图添加到 collectionview 的底部,这样所有东西都可以一起滚动,就好像它们都在同一个 collectionview 中一样。这可能吗?
这是我正在尝试做的图片:https ://i.imgur.com/IAjFeyH.jpg
解决方案
您可以像这样设计 CollectionView:
2部分,第一个为所有红色方块,第二个为另一个viewController的视图
在第 2 节中,返回一个普通单元格,该单元格将另一个 viewController 的视图添加为子视图。
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 1) { UICollectionViewCell *cell = [[UICollectionView alloc] init]; //create a normal cell [cell addSubview:anotherVC.view]; return cell; } }
推荐阅读
- java - Jackson 将 Map 合并到 json 对象中
- laravel - Laravel 项目与 Docker
- libgdx - LibGDX - 黑白图像将黑色渲染为透明,将白色渲染为黑色
- rest - 命名仅因身份验证方案不同的 API
- g1ant - 错误“呼叫被被呼叫者拒绝”是什么意思?
- sql - ActiveRecord 和过滤子查询
- linux - Grep 仅返回第一个匹配结果(不需要)。我该如何防止这种情况?
- java - stringTokenizer 用于读取整数和字符串的错误在哪里?
- c++ - 如何找到支持的 GLSL 版本?
- r - “错误:不知道如何将 RHS 添加到主题对象”在 R 中保存主题格式时