mkko / DrawerView

A drop-in view, to be used as a drawer anywhere in your app
MIT License
375 stars 58 forks source link

Is it possible to attach this to the top of a Tab Bar? #23

Closed osheroff closed 4 years ago

osheroff commented 4 years ago

Hi, Sorry for the request-for-help disguised as an issue.

I'm trying to emulate the podcasts and itunes' app behaviors with DrawerView. This means that I have a "now playing" bar that sits on top of a tab bar, and doesn't change when you switch tabs, which can be expanded with a tap or a swipe.

To that end, I've tried attaching a DrawerView in code (in UITabBarController), trying to add layout constraints to attach the bottom of the drawer view to the top of the tab bar, but any layout constraint I add seems to get rejected immediately. I'm trying this:

class TabBarControllerWithDrawer : UITabBarController {

   override func viewDidLoad() {
        let drawerView = DrawerView()
        drawerView.attachTo(view: self.view)
        drawerView.snapPositions = [.collapsed, .open]

        NSLayoutConstraint(item: drawerView, attribute: .bottom, relatedBy: .equal, toItem: self.tabBar, attribute: .top, multiplier: 1, constant: 0).isActive = true
}

Am I totally on the wrong track? Should I instead be just attaching a shared instance of DrawerView to each of the tab's children? Some other method?

Thanks, Ben

osheroff commented 4 years ago

never mind, i was using the wrong tool, and had the wrong idea about what the interface should do. sorry 'bout that.

mkko commented 4 years ago

Hi Ben,

Sorry I wasn't quick enough to get back at you. Maybe I should document that you generally shouldn't mess with the drawer's layout constraint as they're used to move/animate the drawer.

Did you try to use insetAdjustmentBehavior with a fixed value? Downside of this would be that safe areas wouldn't be updated automatically. Another alternative would be to position the view that contains the drawer so, that its bottom is at the top of the tab bar and setting the view to not clip child views.