Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get notified about unsuccessful back swipe gestures in UINavigationController

I have a UINavigationController subclass, which manages a custom navigation bar. This navigation bar's look depends on the top view controller. I ask the top view controller about the type of the bar to be displayed when -pushViewController:animated: or -popViewControllerAnimated: happens.

The problem is, that the navigation bar type change is played when the user starts swiping but I could not find any event which tells me that the swipe was successful or not, so if the user cancels the swipe, I stuck on the previous view controller with the desired navigation bar look of the one below it in the navigation stack.

I have tried UINavigationControllerDelegate, but neither -navigationController:didShowViewController:animated: nor -navigationController:didShowViewController:animated: gets called. My second thought was to use interactiveGestureRecognizer, but it seems it it ends successfully both on successful and cancelled back swipe, and the topViewController is also still the same when the recognizer event is called.

I know, that the top view controller's -viewDidAppear will be called again upon cancelled swipe, but I don't want my users to implement any logic in their controllers to support my navigation implementation.

Any ideas?

like image 751
gklka Avatar asked Oct 08 '15 21:10

gklka


People also ask

How do I turn off back swipe gestures?

As a side note, to quickly return to default settings without using the ADB command, go to Settings –> System –> Gestures –> System navigation on your device. Tap the gear icon, then adjust the gesture sensitivity slider for the left edge to set things back to normal.

How do I turn off swipe back in iOS?

EDIT. If you want to manage swipe back feature for specific navigation controllers, consider using SwipeBack. With this, you can set navigationController. swipeBackEnabled = NO .

What is Interactivepopgesturerecognizer?

The gesture recognizer responsible for popping the top view controller off the navigation stack. iOS 7.0+ iPadOS 7.0+ Mac Catalyst 13.1+


1 Answers

Try using the UINavigationControllerDelegate, you can rely on its callbacks to know when a viewController is going to be displayed or not.

Getting interactivePopGestureRecognizer dismiss callback/event

like image 111
matanwrites Avatar answered Oct 13 '22 12:10

matanwrites