Search code examples
iosswiftuitabbarcontrolleruitabbarlottie

Is it possible to add Lottie animation to UITabbarViewController when select tab?


Now, I have lottie file animation for tabbar icon but I don't know how to put it when select tab to be animation view.

Has anyone can help me about this or just guide me? Thank you.


Solution

  • Create these function after importing Lottie:

    func showLoadingAnimation(view: UIView) {
        animationView.isHidden = false
        animationView.animation = Animation.named("53175-ball-spinner")
        animationView.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
        animationView.center = view.center
        animationView.contentMode = .scaleAspectFill
        animationView.loopMode = .loop
        animationView.play()
        view.addSubview(animationView)
    }
    
    func hideLoadingAnimation() {
        animationView.stop()
        animationView.isHidden = true
    }
    

    Call them where ever needed as:

    showLoadingAnimation(view: self.view)