azfx / SimpleTab

A Simple iOS Tab Bar Controller with animation support.
MIT License
80 stars 13 forks source link

How to detect selected item simple tabbar #8

Closed leewonghao closed 7 years ago

leewonghao commented 7 years ago

I want to detected method event didSelect if i when press item on tabbar navigation to another view controller.

Please help me! thank you.

azfx commented 7 years ago

You should be able to override an existing style, and hook into animateTabTransition function.

class TestStyle:ElegantTabBarStyle {
    override func animateTabTransition(tabBar: SimpleTabBar, toIndex: Int,fromIndex: Int) {
        super.animateTabTransition(tabBar: tabBar, toIndex: toIndex, fromIndex: fromIndex)
        print(fromIndex, toIndex)
    }
}

And then in AppDelegate, load the style like this: let style:SimpleTabBarStyle = TestStyle(tabBar: simpleTBC!.tabBar)

fromIndex and toIndex should help you determine which tab item got selected and unselected.

leewonghao commented 7 years ago

This is so helpful. Thank you for supported my question.