1

As my title saying is there any way to customize default back button action method ?

I tried to find on Google but not get any answer that fulfill my requirement.

I know one way to Add UIBarButtonItem to self.navigationItem.leftBarButtonItem and customize action method but I will be hide < sign of Back button and I don't want this.

Some R&D that done by Google.

1) How to override self.navigationItem.backBarButtonItem Action?

2) iOS disable animation for NavigationController back button

3) Google Question/Answer

Add image that look like <Back button that is one way but I want to going with native way.

Govaadiyo
  • 5,644
  • 9
  • 43
  • 72

3 Answers3

1

One option is to implement the viewWillDisappear method on the View Controller and set animationEnable No

override func viewWillDisappear(animated : Bool) {
super.viewWillDisappear(animated)
   UIView.setAnimationsEnabled(false)
} 
override func viewDidDisappear(_ animated: Bool) {
      UIView.setAnimationsEnabled(false)
}
Nishant Bhindi
  • 2,242
  • 8
  • 21
  • Will not be helped because I just want to disable animation of moving and viewWillDisappear method call when moving is started – Govaadiyo Aug 22 '17 at 07:08
  • But it will disable animation for all the screens of the App so We need to manage True for all relevant screens – Govaadiyo Aug 22 '17 at 07:45
0

you have to add your custom bar button there...

override func viewDidLoad() {
        super.viewDidLoad()
         let button = UIButton(frame: YourDesiredFrame)
        button.setImage(UIImage(named : "back"), for: .normal)
        button.addTarget(self, action: #selector(backButtonTapped(_:)), for: .touchUpInside)
        let barButton = UIBarButtonItem(customView: button)
        self.navigationItem.backBarButtonItem = barButton
}


    func backButtonTapped(_ sender : UIButton) {
        _ = self.navigationController?.popViewController(animated : false)
    }
Abdul Waheed
  • 863
  • 8
  • 14
0
// Swift 4
override func viewDidDisappear(_ animated: Bool) {
    super.viewDidDisappear(animated)
    // turn on animations
    UIView.setAnimationsEnabled(true)
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    // turn off animations
    UIView.setAnimationsEnabled(false)
}
Kristian
  • 2,071
  • 23
  • 15