52inc / Pulley

A library to imitate the iOS 10 Maps UI.
https://cocoapods.org/pods/Pulley
MIT License
2.02k stars 265 forks source link

How to show a drawer over the current view controller? #391

Closed Multiforge closed 3 years ago

Multiforge commented 4 years ago

Hi, I have a question I hope you can help with. I'm probably missing something super obvious, but I want to show a drawer over an existing view controller that's modal and is already onscreen. I'd like to do this in code, not IB. Here's pseudocode for what I have tried so far:

MyModalViewController.swift (example)

  // if we got here then the Show Drawer button was pressed...
  guard let drawerVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "drawerID") else { assertionFailure(); return }
  let contentVC = self    // show the drawer over currently-displayed VC (instance of MyModalViewController)
  let pulleyVC = PulleyViewController(contentViewController: contentVC, drawerViewController: drawerVC)
  pulleyVC.modalPresentationStyle = .overCurrentContext
  present(pulleyVC, animated: true, completion: nil)

Unfortunately the code above results in a runtime error, 'NSInvalidArgumentException', reason: 'Application tried to present modal view controller on itself. Presenting controller is <Pulley.PulleyViewController: 0x1177b8200>.'

How do I bring up the drawer over the current VC?

Many thanks for any help.

Multiforge commented 4 years ago

ping?

ulmentflam commented 3 years ago

@Multiforge Your root view controller needs to be the PulleyViewController in this case. The best way to bring up the drawer view over the current view controller is by setting the drawer position using the setDrawerPosition(position, animated, completion?) method. Take a look at the sample app to see how the PulleyViewContoller is presented in the view hierarchy.