Interactive Pop Gesture with a Custom Back Button or Hidden Navigation Bar
In iOS 7 Apple introduced a new system-wide gesture for popping items from the
It brings iOS closer to Android in this aspect of usability, but it's not straightforward from the developers' perspective.
There are two situations in which the gesture stops being recognized:
- when the default
backBarButtonItemis replaced with a custom one
- when the navigation controller's
A quick Google search reveals a few posts advising to set
interactivePopGestureRecognizer.delegate = self and calling it a day.
But this solution is actually not bulletproof. During beta tests of Outread we noticed two problems with it:
- swiping back when a view controller is being pushed can cause a weird UI behavior (e.g. a completely missing back button); quick fix to this problem is already presented at keighl
- swiping back repeatedly can cause the gesture to be recognized when there's only one view controller on the stack, which in turn puts a UI in a (I think unexpected by UIKit engineers) state where it stops recognizing any gestures
I've fixed these problems by subclassing
UINavigationController and disabling the gesture: 1) during push animations, and 2) when
-viewControllers count is less than two.
To enable these fixes simply use
AHKNavigationController instead of
UPDATE: Since 1.1
AHKNavigationController uses delegate forwarding introduced by Peter Steinberger in Fixing UITextView on iOS 7, so it should be easy to use in any project.