Minitour / AZTabBarController

A custom tab bar controller for iOS written in Swift 4.2
MIT License
348 stars 65 forks source link

ShouldMoveToTabAtIndex #10

Closed styldimitriou closed 7 years ago

styldimitriou commented 7 years ago

Hey there!

Is there a way to either disable a tab bar button or add an action to prevent navigating to the viewController assigned to this button?

Perhaps a shouldMoveToTabAtIndex function would be useful.

Minitour commented 7 years ago

@stelarelas Ok I created the delegate function, I will be updating the pod in few minutes. This is how you use it:

func tabBar(_ tabBar: AZTabBarController, shouldMoveToTabAtIndex index: Int) -> Bool {
        return !(index == 3)
}

I also recommend you add this to disable the animation at the disabled index:

func tabBar(_ tabBar: AZTabBarController, shouldAnimateButtonInteractionAtIndex index: Int) -> Bool {
        return !(index == 3)
}

Please note that this will simply disable the transition from controller to controller. If you have actions set on that index they will be triggered when clicking the tab.

styldimitriou commented 7 years ago

Working like a charm!

Thank you very much @Minitour! Your assistance is greatly appreciated!

Minitour commented 7 years ago

Happy to help 😊