New gesture - Swipe left to right - as shortcut for Back button in UINavigationController in old app

后端 未结 2 625
甜味超标
甜味超标 2021-01-06 00:07

iOS 7 sports a new gesture, swiping left to right across the screen as a shortcut for the Back button in a UINavigationController.

My app does not seem to be picking

相关标签:
2条回答
  • 2021-01-06 00:35

    It should work automatically if the back button is visible. If you are displaying a leftBarButtonItem instead of the back button, the gesture will not be present by default. Also, if you are using a UINavigationBar but not a UINavigationController, you won't see this functionality.

    If you are using a UINavigationController and your view controller's navigation item contains a leftBarButtonItem, it's still possible to add functionality for the swipe left to right gesture of the navigation controller, by attaching a delegate to the navigation controller's interactivePopGestureRecognizer.

    EDIT: I didn't notice that you're building against SDK 5.1. This is a new feature in the iOS 7 SDK, so I believe you'll need to build with Xcode 5 against the iOS 7 SDK in order to make use of the new feature.

    0 讨论(0)
  • 2021-01-06 00:47

    I have found the perfect solution for custom leftBarButtom problem

    Set the gesture delegate to the navigation controller

    you need to subclass UINavigationController and implement "UIGestureRecognizerDelegate" protocol in it, and add some code on viewDidLoad see the following code below

    CustomNavigationController.m

    @interface CBNavigationController : UINavigationController @end

    @implementation CBNavigationController

    • (void)viewDidLoad { __weak CBNavigationController *weakSelf = self;

      if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.interactivePopGestureRecognizer.delegate = weakSelf; } }

    @end

    and just inherit this class to your Navigation controller, it will work perfect.

    0 讨论(0)
提交回复
热议问题