Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of unresolved identifier 'kCAFillModeForwards'

When I try to set animation.fillMode = kCAFillModeForwards Xcode can't compile and display an error. "Use of unresolved identifier 'kCAFillModeForwards'".

I've already used this in previous projects without any issues, did somebody already encountered this behaviour?

func animateGradient() {
        currentGradient += 1
        let animation = CABasicAnimation(keyPath: Animation.keyPath)
        animation.duration = animationDuration
        animation.toValue = currentGradientSet()
        animation.fillMode = kCAFillModeForwards
        animation.isRemovedOnCompletion = false
        animation.delegate = self
        gradient.add(animation, forKey: Animation.key)
}
like image 477
Julien Avatar asked Dec 06 '22 11:12

Julien


1 Answers

That constant has been removed in favor of a forwards property on the CAMediaTimingFillMode type. As of Swift 4.2 the same thing is written as:

animation.fillMode = .forwards

That said, the combination of a forward fill mode and not removing the animation when it completes is often misused in an attempt to make an animation "stick"/"remain". Unless you are animating the removal of a layer, a cleaner solution is to update the layer to the new value and add an animation—which is removed when it completes—to transition from the previous value.

like image 123
David Rönnqvist Avatar answered Jan 04 '23 23:01

David Rönnqvist