4

animation

Situation

I have a UIView that has a layout constraint to the bottom of the safe area. This is inside a UIViewController inside a UINavigationController. It works fine when the navigation bar is in-between the large title and the "regular" title. However when bouncing lower the UINavigationBar covers the custom view.

Question

How can I lock the position of a custom view to the bottom of a bouncing NavigationBar. Storyboard solution would be optimal, Swift solution would be sufficient.

Hans
  • 2,354
  • 3
  • 25
  • 35

1 Answers1

3

You need to add menuView in navigationBar

let menuView = UIView()
menuView.backgroundColor = .red
menuView.translatesAutoresizingMaskIntoConstraints = false

self.navigationController?.navigationBar.addSubview(menuView)

[menuView.leadingAnchor.constraint(equalTo: (self.navigationController?.navigationBar.leadingAnchor)!),
menuView.topAnchor.constraint(equalTo: (self.navigationController?.navigationBar.bottomAnchor)!),
menuView.trailingAnchor.constraint(equalTo: (self.navigationController?.navigationBar.trailingAnchor)!),
menuView.heightAnchor.constraint(equalToConstant: 60)].forEach{ $0.isActive = true }

Result

enter image description here

But you have to maintain contentInset of UITableView/UICollectionView/UIScrollView & Scroll indicator

Suggestions

Use Section Header of TableView/CollectinView in this type of situation.

Jay Patel
  • 2,642
  • 2
  • 18
  • 40