phimage / CustomSegue

Custom segue for OSX Storyboards with slide and cross fade effects (NSViewControllerTransitionOptions)
MIT License
121 stars 12 forks source link

View controllers below the current view controller are receiving click events #3

Open ivanmkc opened 8 years ago

ivanmkc commented 8 years ago

Hi,

When I click a cell on my table view controller, it opens up a new screen using your a SlideLeftSegue. However on this new screen, when I click an empty spot, the cells underneath it receive the click and segues again.

Why does the screen below still get click events and how do I prevent this?

Many thanks, Ivan

phimage commented 8 years ago

I am not very confident to handle this in all situations so I make a bool removeFromView When configuring the segue

class MyViewController: NSViewController {

  override func prepareForSegue(segue: NSStoryboardSegue, sender: AnyObject?)
      if segue.identifier == "myseguename" {
          if let segue = segue as? PresentWithAnimatorSegue, animator = segue.animator as? TransitionAnimator {
              animator.removeFromView = true
          }
      }
  }

This will remove temporary the source controller from the view hierarchy (by replacing it with an empty view)

Sometimes in my code I override some view functions to stop mouse event to propagate

class MyView: NSView {
    override func mouseDown(theEvent: NSEvent) {
      // pass event only to wanted element, call preventDefault etc...
    }
    override func acceptsFirstMouse(theEvent: NSEvent?) -> Bool {
        return true
    }
}