eggswift / ESTabBarController

:octocat: ESTabBarController is a Swift model for customize UI, badge and adding animation to tabbar items. Support lottie!
MIT License
5.17k stars 578 forks source link

The tab bar will select multiple items when I click quickly #229

Closed zyflovelam closed 4 years ago

zyflovelam commented 4 years ago

screen record

OS: 10.15.3 Xcode: 11.3.1 (11C504) Language: Swift 4.2

zyflovelam commented 4 years ago

TabBarItemContentVIew:

class BMTabBarContentView: ESTabBarItemContentView {
    public var duration = 0.5

    override init(frame: CGRect) {
        super.init(frame: frame)

        textColor = R.color.fourth()!
        highlightTextColor = R.color.primary()!

        iconColor = R.color.fourth()!
        highlightIconColor = R.color.primary()!
        renderingMode = .alwaysOriginal
        itemContentMode = .alwaysOriginal
        titleLabel.font = FontUtil.regular(size: 10)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func deselectAnimation(animated: Bool, completion: (() -> ())?) {
        imageView.layer.removeAllAnimations()
        completion?()
    }

    override func selectAnimation(animated: Bool, completion: (() -> ())?) {
        self.bounceAnimation()
        completion?()
    }

    override func reselectAnimation(animated: Bool, completion: (() -> ())?) {
        self.bounceAnimation()
        completion?()
    }

    private func bounceAnimation() {
        let animation = CAKeyframeAnimation(keyPath: "transform.scale")
        animation.values = [1.0, 1.25, 0.9, 1.15, 0.95, 1.02, 1.0]
        animation.duration = duration
        animation.calculationMode = CAAnimationCalculationMode.cubic
        imageView.layer.add(animation, forKey: "bm:tabBar:select:animation")
    }
}
zyflovelam commented 4 years ago

Am I doing something wrong?

eggswift commented 4 years ago

your animation duration

zyflovelam commented 4 years ago

What should I do now? I have been removed the animation when the item deselected. and another thing happened, same as this thing, I tapped items quickly, 'Free Books' first, and then 'Community', and now, 'Free Books' still highlight, and 'Community' still unselect like before. and also, the 'Community Controller' displayed.

zyflovelam commented 4 years ago

Could you help me, please?

zyflovelam commented 4 years ago

your animation duration