iOS: Removing UINavigationBar animation

大城市里の小女人 提交于 2019-11-29 18:04:17
Marcus Leon

Figured this out in large part due to this answer https://stackoverflow.com/a/8602982/47281

Create a custom Nav Bar and override popItem:

class MyNavigationBar: UINavigationBar {
    override func popItem(animated: Bool) -> UINavigationItem? {
        return super.popItem(animated: false)
    }
}

Entered MyNavigationBar as the Navigation Bar class for our Navigation Controller via the Storyboard:

Note I did not override NavigationController popViewControllerAnimated as in the linked answer.

You can do this:

override func viewDidLoad() {
    super.viewDidLoad()
    let logoImage: UIImage = UIImage(named: "ABC")!
    self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: logoImage, style: .plain, target: self, action: #selector(backBtnPressed))
}

And then create a method to handle the tap on the button

func backBtnPressed(){
    _ = self.navigationController?.popViewController(animated: false)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!