Swift animatewithDuration() instantly completes

152 views Asked by At

So, I have this code:

UIView.animate(withDuration: 10.0, delay: 0, options: .curveLinear , animations: { 
            self.gameLabel.alpha = 0
}, completion: nil)

The problem is when this code is called it instantly goes to a 0 alpha and doesn't slowly transition. What am I doing wrong?

Here is some more context for the the code:

var gameLabel = SKLabelNode()

override func didMove(to view: SKView) {
    gameLabel.fontColor = UIColor.white
    gameLabel.fontSize = 85
    gameLabel.setScale(0.40)
    gameLabel.text = "this is a game"
    gameLabel.position = CGPoint(x: 0, y: 0)
    gameLabel.zPosition = 0
    gameLabel.alpha = 1

    addChild(gameLabel)   
}

func touchDown(atPoint pos : CGPoint) {
    UIView.animate(withDuration: 2, animations: {
            self.gameLabel.alpha = 0
    })
}
1

There are 1 answers

1
Sam Hoffmann On

So, i solved my problem by running.

self.gameLabel.run(SKAction.fadeOut(withDuration: 10))