Navigate with PKRevealController

I have a PKRevealController with front and right views. The panda gesture is on, so I can open the right view with a swipe - fine. Scrolling in a different way does nothing, as it should not, because there is no open controller to open - excellent. So instead, I want to implement swipe (from left to right) that will trigger my navigation backwards.

I added a gesture recognizer to my (front) view controller - nothing happens.

If I set RecognizesPanningOnFrontView: NO on the distribution controller, then my newly added gesture recognizer works - I can go back.

So now this is either one or the other. I want both. How can i do this?

+4
source share
1 answer

I implemented my own solution. The two solutions are actually, since I need different ones for the cases when I allowed and rejected PKRevealController actions.

Case 1 : setRecognizesPanningOnFrontView:NO

This case is pretty simple - I just add a UISwipeGestureRecognizer which calls my back method:

 UISwipeGestureRecognizer *backSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(back)]; [backSwipe setDirection:UISwipeGestureRecognizerDirectionRight]; [self.view addGestureRecognizer:backSwipe]; 

Case 2 : setRecognizesPanningOnFrontView:YES

This is a little trickier. To avoid a gesture recognition conflict, I had to click on the PKRevealController gesture PKRevealController . Of course, I only implemented this when the PKRevealController does not have a leftViewController .

So, I register the class that I want to implement navigation from the back, as a listener for notifications:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(back:) name:NOTIFICATION_BACK_SWIPE object:self]; 

And then in the PKRevealController.m file, in - (void)moveFrontViewRightwardsIfPossible , just post a notification:

 [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_BACK_SWIPE object:[(UINavigationController *)self.frontViewController topViewController]]; 

Here I pass as the notification object the receiver of the UIViewController . I do this so that only this particular instance of the UIViewController responds to this notification. Otherwise, if you had more UIViewControllers in the UINavigationController stack that are subscribed to receive this notification, all of them will lead to the UINavigationController to the popViewController , which will lead to a random number of steps backward, as long as we want this to happen only once.

What is it. Enjoy it.

+2
source

Source: https://habr.com/ru/post/1492273/


All Articles