I've implemented my own solution. Two solutions actually, as I needed different ones for cases when I allowed and disallowed PKRevealController
swipe actions.
Case 1: setRecognizesPanningOnFrontView:NO
This case is quite easy - I simply add a UISwipeGestureRecognizer
that 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 one is slightly more complicated. In order to avoid gesture recogniser conflict, I had to tap into PKRevealController
's gesture recogniser. Of course, I implemented this only when PKRevealController
does not have a leftViewController
.
So, I register the class which I want to implement the back swipe navigation as a listener to notifications:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(back:)
name:NOTIFICATION_BACK_SWIPE
object:self];
And then in PKRevealController.m file, in - (void)moveFrontViewRightwardsIfPossible
method, simply post the notification:
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_BACK_SWIPE object:[(UINavigationController *)self.frontViewController topViewController]];
Here I am passing as notification's object the recipient UIViewController
itself. I'm doing this so that only that specific UIViewController
instance reacts to this notification. Otherwise if you had more UIViewControllers
in the UINavigationController
stack that are subscribed to receive this notification, they would all cause the UINavigationController
to popViewController
, which would result in a random number of steps back while we want this to happen only once.
That's it. Enjoy.