Search code examples
iosuisplitviewcontrollerrubymotion

Is it possible to close the menu ( split screen ) dynamically


I've been working on a RubyMotion project and I'm using the UISplitViewController, but I was wondering: is it possible to close the side screen ( so the screen that's hidden ) programmatically?

I guess this is a private API in iOS, but I'm not sure or this is true. I'm able to close the split screen with a tap on someplace else on the screen ( default iOS behavior ), but I can't find the function that creates that effect.

I've been searching on the web for this, but I couldn't find any answer to this question. Hope you guys can help me out.

Cheers.


Solution

  • To accomplish this, you will need to use the UISplitViewController Delegate and implement splitViewController:shouldHideViewController:inOrientation:.

    The assigned delegate could then have an attribute that is changed between true/false when a button is pressed.

    In your splitViewController:shouldHideViewController:inOrientation: you would then return that attribute to say whether the master view should be shown or not.

    Then finally, when the button is pressed, you will also need to call setNeedsLayout to force it to redraw and call the delegate method.

    # Button Touch Handler
    def hideShowMasterViewButtonPressed(sender)
      self.hideMasterView = !self.hideMasterView
      self.splitViewController.view.setNeedsLayout
    end
    
    # Delegate Method
    def splitViewController(svc, shouldHideViewController:vc, inOrientation:orientation)
      self.hideMasterView
    end
    

    This is where I got the idea.