matthewcheok / MCPanelViewController

Drop-in panel control for iOS with blurring background and screen-edge activation gestures.
MIT License
324 stars 25 forks source link

Interactive pop gesture causes problems if panel is a navigation controller #4

Closed johnrogers closed 11 years ago

johnrogers commented 11 years ago

I am instantiating your panel view controller the same way you do in the demo - via a storyboard, a view controller embedded in a navigation controller.

I found that if you traverse a navigation controller, then go back to the root view controller and present the panel view controller over the top of it, you could actually trigger the interactive pop gesture recogniser and it would mess up the view hierarchy. I added the following to get it to work:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [[[self navigationController] interactivePopGestureRecognizer] setEnabled:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
        [super viewWillDisappear:animated];
    [[[self navigationController] interactivePopGestureRecognizer] setEnabled:YES];
}    
matthewcheok commented 11 years ago

I couldn't replicate your issue about messed up view hierarchy. The interactivePopGestureRecognizer of UINavigationController always takes precedence over the UIScreenEdgePanGestureRecognizer of MCPanelViewController. If that's not the desired effect, I think your solution is the best.

I did discover a bug if you have MCPanelViewControllers created then added screen edge gestures to UINavigationController's view expecting to attach them to view controller that could be later pushed or popped off screen. There are now methods to remove gesture recognizers for this scenario.

johnrogers commented 11 years ago

Awesome. It's probably worth noting that self.navigationController may be nil in viewWillAppear/viewDidDisappear. In my experience I find it's better to reference the navigation controller from viewDidAppear/viewWillDisappear. That way you're guaranteed a reference to the navigation controller before it's removed from the view hierarchy (assuming you've added the view controller to a navigation controller in the first place).

Regarding the messed up view hierarchy: you have to be really fast. If you push a few view controllers onto the stack, pop them all off and open up the panel. Swiping from the left edge (or right edge, depending how the panel is configured), really quickly, will SOMETIMES cause the panel to be popped and display the next view controller on the NC's stack. Not always, but sometimes. This could be a bug with the interactive pop gesture recogniser - who knows. It's solved by simply disabling the pop gesture recogniser as above, though.