Ramotion / animated-tab-bar

:octocat: RAMAnimatedTabBarController is a Swift UI module library for adding animation to iOS tabbar items and icons. iOS library made by @Ramotion
https://www.ramotion.com/animated-tab-bar-ios-app-development-ui-library/
MIT License
11.13k stars 1.33k forks source link

Detect which TabBarItem is Selected #107

Closed sentiasa closed 6 years ago

sentiasa commented 8 years ago

I have a question. Through container.tag (in RAMAnimatedTabBarController) we can access which Tab Bar Item is clicked. How can I get which item is clicked inside playAnimation() level?

So I can use index number to apply different images for different tabBarItems

override public func playAnimation(icon : UIImageView, textLabel : UILabel) {
    var index = Get index of the TabBarItem pressed

    if index == 0 {
        // change img for left TabBarItem 
    } else if index == 5 {
      // change img for right TabBarItem
    }
}

I tried something like: RAMAnimatedTabBarController.tabBar() etc, but doesn't let me do that.

Can you please help me? Thanks

RajChanchal commented 7 years ago

Any solution to above query yet??

RajChanchal commented 7 years ago

Well, I have found a workaround. For that you need to subclass you tabbarcontrollerto RAMAnimatedTabBarController Then in the subclass ovveride the super class' method 'tapHandler'

override func tapHandler(_ gesture: UIGestureRecognizer) {
        super.tapHandler(gesture)
        guard let items = tabBar.items as? [RAMAnimatedTabBarItem],
        let gestureView = gesture.view else {
        fatalError("items must inherit RAMAnimatedTabBarItem")
        }
        let currentIndex = gestureView.tag
    }
furiosFast commented 6 years ago

can you explain yourself better? Thank's