Here is a ViewControllerA push a ViewControllerB, and in the ViewControllerB the leftBarButtonItem is set as following:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked:)];

After setting the leftBarButtonItem, the Back swipe gesture is not work. Is it possible to keep the swipe gesture?

有帮助吗?

解决方案

Because you've changed the left bar button item, you're telling the navigation controller to stop managing the navigation-based back-actions that the user can take.

To fix it, you can tell the navigation controller to continue accepting those gestures on the current view controller by using:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

Where self if your view controller.

UIViewController privately implements UIGestureRecognizerDelegate, so you'll get a warning for this, but you can mitigate this by adding in the protocol conformance (<UIGestureRecognizerDelegate>) to your header, or to a class extension.

其他提示

try to set interactivePopGestureRecognizer to nil

override func viewDidLoad() {
    super.viewDidLoad()
    self.interactivePopGestureRecognizer!.delegate = nil;

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top