Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace back button but keeping swipe to navigate back

First of all, I have noticed that there is a similar question. However, I would like to ask about the solution in Swift. Here is my code:

override func viewDidLoad() {
    super.viewDidLoad()
    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Button", style: .Plain, target: self, action: nil)
}

I want to replace the back button but keeping the swipe for user to navigate back. However, this disables the swipe. I cannot get the accepted answer and the suggested answer in the link above to work. Here is what I tried to translated into Swift.

let appearanceNavigationBar = UINavigationBar.appearance()
appearanceNavigationBar.backIndicatorImage = UIImage(named: "back")
appearanceNavigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")
appearanceNavigationBar.tintColor = UIColor.whiteColor()

I am using Xcode 8.0 beta, Swift 2.3 and testing in iOS 10.0. Any help would be greatly appreciated.

like image 865
Joshua Avatar asked Dec 05 '22 00:12

Joshua


1 Answers

I used this and it worked:

self.navigationController.interactivePopGestureRecognizer.delegate = nil;
like image 72
Proton Avatar answered Dec 14 '22 21:12

Proton