I have custom back buttons all over my app and it looks like navigation controller does not like it.
So, I want the iOS7 swipe-to-go-back gesture to work along with my custom back buttons. Searched and tried different ways but none seems to be promising. The closest I could get is with http://keighl.com/post/ios7-interactive-pop-gesture-custom-back-button/. However, Now when I keep pushing and popping the navigation stack, after sometime the rootViewController in the stack stops responding to any touch.
Any suggestions?
Even I had the same problem, I have fix it by modifying code provide in the link which you are referring . Now My screens freezes very rarely still finding for permanent fix.
Subclassing UINavigationController, like keighl is suggesting, is the right approach imo. But he's missing a check for the root view controller to avoid freezing when the gesture is executed on the root view. Here's a modified version with the additional check:
CBNavigationController.h:
CBNavigationController.m:
objective-c
Here's a simple Swift subclass of
UINavigationController
you can use that I adapted from @weak's answer. There shouldn't be a need to implementUIGestureRecognizerDelegate
as the nav delegate'snavigationController(_:didShow:animated:)
handles the work of enabling and disabling the pop gesture.Using this subclass in your storyboard or code is easier than doing a one-off disabling in your other controllers that are embedded in nav controllers.
I've got the same problem, here is my solution: In your custom NavigationController, like
MYNavigationController
, cause you set the gesture delegate to the navigationController, you can add the delegate method there :Here is my answer to a similar question asked here
You can use a little trick to get the native gesture working. Create a subclass of
UINavigationItem
, then overrideleftBarButtonItems
method:Now use this class for the item that has custom left
UIBarButtonItem
. The gesture works! This is becauseUINavigationController
thinks there are no left items and enables the gesture. You are still able to access your custom item through theleftBarButtonItem
property.