iOS: Removing UINavigationBar animation

烂漫一生 提交于 2019-12-18 09:49:55

问题


Our app has an UINavigationBar with an image on it. When we segue (push) to another screen then click the back button the image on the Navigation Bar seems to animate from left to right as it reappears. This is a little distracting. How can you remove this back button animation?

We tried changing the segue Animates setting but this changes both the push animation and not the back animation.

Our Nav Bar code:

    let logoImage:UIImage = UIImage(named: "ABC")!
    viewController.navigationItem.titleView = UIImageView(image: logoImage)

回答1:


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.




回答2:


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)
}


来源:https://stackoverflow.com/questions/42774136/ios-removing-uinavigationbar-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!