@@ -337,25 +337,13 @@ public class CVColorOrGradientView: ManualLayoutViewWithLayer {
337337
338338 dimmerLayer. removeAllAnimations ( )
339339
340- // Animate fade-in.
341- let fadeIn = CABasicAnimation ( keyPath: #keyPath( CALayer . opacity) )
342- fadeIn. fromValue = 0
343- fadeIn. toValue = 1
344- fadeIn. duration = stepDuration
345- fadeIn. fillMode = . forwards
346- fadeIn. isRemovedOnCompletion = false
347- dimmerLayer. add ( fadeIn, forKey: " fadeIn " )
348-
349- // Schedule fade-out after delay.
350- DispatchQueue . main. asyncAfter ( deadline: . now( ) + 2 * stepDuration) {
351- let fadeOut = CABasicAnimation ( keyPath: #keyPath( CALayer . opacity) )
352- fadeOut. fromValue = 1
353- fadeOut. toValue = 0
354- fadeOut. duration = stepDuration
355- fadeOut. fillMode = . forwards
356- fadeOut. isRemovedOnCompletion = false
357- dimmerLayer. add ( fadeOut, forKey: " fadeOut " )
358- }
340+ let animation = CAKeyframeAnimation ( keyPath: #keyPath( CALayer . opacity) )
341+ animation. values = [ 0 , 1 , 1 , 0 ]
342+ animation. keyTimes = [ 0 , 1.0 / 3.0 , 2.0 / 3.0 , 1 ] . map { NSNumber ( value: $0) }
343+ animation. duration = stepDuration * 3
344+ animation. fillMode = . forwards
345+ animation. isRemovedOnCompletion = false
346+ dimmerLayer. add ( animation, forKey: " dimming " )
359347 }
360348}
361349
0 commit comments