How to stack UICollectionView sections

£可爱£侵袭症+ 提交于 2019-12-23 08:29:08

问题


I originally tried doing this with two UICollectionViews stacked on top of each other. However getting it to scale right was nightmare with Auto-layout (I'm a novice iOS developer so that is more a critique of my skill than Auto-layout). I'd like to stack two sections of UICollectionView cells on top of each other like this:

             +----------------------+
             |+-Section 0---------->|
             | +-------+  +-------+ |
             | |       |  |       | |
             | |       |  |       | |
             | |Cell 0 |  |Cell 1 |+->
             | |       |  |       | |
             | |       |  |       | |
             | +-------+  +-------+ |
             +--Section 1---------->|
             | +-------+  +-------+ |
             | |       |  |       | |
             | |       |  |       | |
             | |       |  |       | |
             | |Cell 0 |  |Cell 1 |+->
             | |       |  |       | |
             | |       |  |       | |
             | +-------+  +-------+ |
             |                      |
             +----------------------+

I'm using a custom Flow Layout, but I'm not even sure where to begin breaking my current 2 sections to stack like this. Currently my sections are stacked like this:

                                +--------(Offscreen)
                                |
                                +
          +--------xxxx--------+v
          |   Section 1        | Section 2
          |  +-----+   +-----+ | +-----+  +-------+
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  +-----+   +-----+ | +-----+  +-------+
          |                    |
          |                    |
          |  +-----+   +-----+ | +-----+  +-------+
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  |     |   |     | | |     |  |       |
          |  +-----+   +-----+ | +-----+  +-------+
          |                    |
          |                    |
          |        xxxx        |
          +--------xxxx--------+

回答1:


UICollectionView can scroll either vertical or horizontal not both. If you have only two sections like in the diagram you can use two collection view. But it better to think of a design like a table view contains collection views in each cells. So that the design will be flexible(Horizontal and vertical scrolling with any number of sections). Anyway the design is little bit complex, you should customize the table view cell to put collection view in it. Now the UITableView will give you vertical scrolling with the ability to scroll each rows horizontaly(UICOllectionView)



来源:https://stackoverflow.com/questions/20234915/how-to-stack-uicollectionview-sections

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!