CosmicMind / Motion

A library used to create beautiful animations and transitions for iOS.

Home Page:http://cosmicmind.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to hide back button when using UINavigationController transition

guoyingtao opened this issue · comments

I want to use my own back button when I push an UIViewController by UINavigationController transition. I tried navigationItem.setHidesBackButton(true, animated: true), but it did not work.

When you say you want to use your own back button, do you mean changing the image? If so, you only need to set the NavigationBar.backButtonImage property. Here is one option of how to do so:

class AppNavigationController: NavigationController {
    open override func prepare() {
        super.prepare()
        
        guard let v = navigationBar as? NavigationBar else {
            return
        }

        v.backButtonImage = Icon.cm.arrowBack
    }
}

If you need any further help, please reopen this issue. Thank you!

Thanks for your reply.
My problem is that I have an UIViewController which has two status: normal and edit mode. When it is in edit mode, I want to change "back button" to another button and when it is in normal model, I want to change it to "back button" again. So what I want to do is to hide the "back button" when edit mode.

If you use the ToolbarController, it looks identical to the NavigationController, and allows that sort of customization. Take a look at that, and it may work better for you. Otherwise, I can look into a solution with the NavigationController with you.

Thanks for your reply!
I am using a normal UIViewController not ToolbarController.

What I mean is, instead of the NavigationController, use a ToolbarController. You can have the same animations and fully control the Toolbar at top.