iOS disable animation for NavigationController bac

2019-08-09 03:32发布

I want to disable the animation when i pop a ViewController with the back button in NavigationController.

I tried:

override func viewWillDisappear(animated: Bool) {
    super.viewWillDisappear(false)
}

But it still animates.

4条回答
甜甜的少女心
2楼-- · 2019-08-09 04:06

If you want to custom animation maybe try this:

override func viewDidLoad() {
    super.viewDidLoad()

navigationController?.navigationBar.tintColor = UIColor.white
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "◁", style: .plain, target: self, action: #selector(backTapped(sender:)))

}

// with fade animations

@objc func backTapped(sender: UIBarButtonItem) {
    let transition: CATransition = CATransition()
    transition.duration = 0.5
    transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeIn)
    transition.type = CATransitionType.fade
    self.navigationController!.view.layer.add(transition, forKey: nil)
    navigationController?.popViewController(animated: false)
  }

// "◁" added this way: Edit -> Emoji & Symbols

查看更多
闹够了就滚
3楼-- · 2019-08-09 04:16

In the Controller that you want to have that button:

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

func backTapped(sender: UIBarButtonItem) {
    navigationController?.popViewControllerAnimated(false)
}

Take into account that this way, you will lose the < icon on the back button (since you're overriding that button). However, I think it is not possible to have a custom behaviour and the < icon at the same time (unless you add the < icon as an image by yourself)

查看更多
时光不老,我们不散
4楼-- · 2019-08-09 04:18

You can try this

override func viewWillDisappear(animated: Bool) {
    self.navigationController?popViewControllerAnimated(false)
}
查看更多
5楼-- · 2019-08-09 04:22

viewWillDisappear() doesnt handle the animation, its just.

If you're using a UINavigationController

self.navigationController?popViewControllerAnimated(false)

If you're just using UIViewController

self.dismissViewControllerAnimated(false, completion: nil)
查看更多
登录 后发表回答