qmathe / DropDownMenuKit

UIKit drop down menu, simple yet flexible and written in Swift
Other
303 stars 38 forks source link

Feature request - overlay view in outer view controller #26

Open gerchicov-bp opened 5 years ago

gerchicov-bp commented 5 years ago

In my case UITabBarController is root. So if I add this control into inner navigation bar then it won't overlay UITabBar and UITabBarController is still clickable

qmathe commented 5 years ago

Hi,

ok, I understand the problem. I'll take a look at what I can do and come back to you. If you have any solution to solve this, let me know.

qmathe commented 5 years ago

I took a look at various approaches to solve your problem. I thought about two solutions:

The first option is the easiest but doesn't always play well with a transparent navigation bar, since the background view cannot be drawn under the navigation bar anymore. The second option is probably the best choice in your case, unless the menu is too long and needs to be scrollable (with this option it wouldn't extend all the way to the bottom).

To support the second option, I introduced a new API to support custom hide/show transitions for DropDownMenu. You can use this API to:

The changes have been committed in master (using Swift 5). Now you can write something like this to have the tab bar appearing under the menu overlay:

let footer = UIView()

func viewDidLoad() {
    super.viewDidLoad()

    let tabView = tabBarController.view

    footer.translatesAutoresizingMaskIntoConstraints = false
    footer.isHidden = false
    footer.backgroundColor = .black
    footer.alpha = 0
    tabView.addSubview(footer)

    NSLayoutConstraint.activate([
        footer.widthAnchor.constraint(equalTo: tabView.widthAnchor),
        footer.topAnchor.constraint(equalTo:  tabBarController.tabBar.topAnchor),
        footer.bottomAnchor.constraint(equalTo: tabView.bottomAnchor),
        footer.leftAnchor.constraint(equalTo: tabView.leftAnchor)
    ])

    navigationBarMenu.transition.show.append(.init(
        before: { self.footer.isHidden = false },
        change: { self.footer.alpha = 0.7 }
    ))
    navigationBarMenu.transition.hide.append(.init(
        change: { self.footer.alpha = 0 },
        after: { self.footer.isHidden = true }
    ))

    footer.addGestureRecognizer(UITapGestureRecognizer(
        target: navigationBarMenu,
        action: #selector(DropDownMenu.tap(_:))
    ))

}