AladinWay / TransitionButton

UIButton sublass for loading and transition animation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

animation inside completion block does not Animte

minaMagedNaeem opened this issue · comments

If I put an animation block inside the stop animation completion block, It does not animate anything. Here is a sample code:

@IBAction func redeemPPressed(_ sender: Any) {
        let button = sender as! TransitionButton
        button.startAnimation() // 2: Then start the animation when the user tap the button
        let qualityOfServiceClass = DispatchQoS.QoSClass.background
        let backgroundQueue = DispatchQueue.global(qos: qualityOfServiceClass)
        backgroundQueue.async(execute: {
            
            sleep(1) // 3: Do your networking task or background work here.
            
            DispatchQueue.main.async(execute: { () -> Void in
                // 4: Stop the animation, here you have three options for the `animationStyle` property:
                // .expand: useful when the task has been compeletd successfully and you want to expand the button and transit to another view controller in the completion callback
                // .shake: when you want to reflect to the user that the task did not complete successfly
                // .normal
                
                button.stopAnimation(animationStyle: .normal,revertAfterDelay: 1.0,completion: {
                    UIView.animate(withDuration: 1.0, animations: {
                        button.isHidden = true
                        self.codeView.isHidden = false
                    })
                })
            })
        })
    }