UICollectionView and UIView into UIScrollView

2019-07-23 07:00发布

I need to know how to do to embed a UICollectionView and a UIView within a UIScrollView, but that everything moves with the scroll of UIScrollview.

the layout is something like the following image:

Layout

2条回答
可以哭但决不认输i
2楼-- · 2019-07-23 07:24

1- Drag a UIScrollview to your vc give it leading , trailing , top and bottom constraints to the parent view

2- Drag a UIView (content-view) in side the scrollview , give it leading , trailing , top and bottom constraints to the scrollview

3- Control drag from the content-view to the main outer view and select Equal-Widths

4- Drag UIView inside the content-view give it leading , trailing , top and a height say 300

5- Drag UIcollectionView below the top-view give it leading , trailing to the content-View , top to the top-View and a height as you want

6- Hook bottom constraint of the collectionview to the bottom of the content-View

7- set bounces property of the collectionView to false

note: You may hook the height constraint of the collection-view and change in runtime , also it's better to use tableView instead of collection view in presenting data vertically

查看更多
冷血范
3楼-- · 2019-07-23 07:27

Why don't you use the view as the collectionView's section supplementary view (see docs)? It will become part of the collectionView thus scrolling of the collectionView will handle also the view itself.

查看更多
登录 后发表回答