Skip to content

animation inside completion block does not Animte #45

@minaMagedNaeem

Description

@minaMagedNaeem

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
                    })
                })
            })
        })
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions