首页 > 解决方案 > 将视图控制器的视图添加到集合视图的底部以滚动?

问题描述

我有一个包含两个视图控制器的视图。第一个视图控制器包含一个集合视图(蓝色),其框架占据了整个视图。在这个 collectionview 中有许多滚动的对象(红色方块)。我想将第二个 viewcontroller 的视图添加到 collectionview 的底部,这样所有东西都可以一起滚动,就好像它们都在同一个 collectionview 中一样。这可能吗?

这是我正在尝试做的图片:https ://i.imgur.com/IAjFeyH.jpg

标签: ios

解决方案


您可以像这样设计 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;
        }
    }
    

推荐阅读