How to prevent Large Title from Collapsing

前端 未结 3 1604
小蘑菇
小蘑菇 2021-01-01 23:50

The question is simple, how can I prevent a Large Title Navigation Bar from collapse when a scrollview scrolls down?

My navigation must have a large navigation bar a

3条回答
  •  别那么骄傲
    2021-01-02 00:00

    A workaround i figured out is to add a placeholder view that is not CollectionView/TableView as the very first view in ViewController's base view. This first view will be attached to the top of the safeArea, height can be zero.

    Using Storyboard/Xib:

    See the below screenshot for this view with constraints

    Next add another UIView to serve as a container view for your TableView/CollectionView. This container's top will be attached to bottom of the placeholder view. See the below screenshot for constraints of container view and TableView/CollectionView.

    The key here is the first view in the view hierarchy as the navigation bar will check that to set the collapsing effect. Once it does not find it as a CollectionView/TableView, it will not collapse on scrolling.

    Programmatically:

    If you are setting up view's programmatically then you just need to add a placeholder view at the top.

    e.g,

    self.view.addSubview(UIView(frame: .zero))
    self.view.addSubview(tableView) // or collectionView
    

提交回复
热议问题