Created
July 30, 2019 00:08
-
-
Save edudnyk/320b7dbec9a8f591a740377477c8b504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static func animationsForAlphaSwap(forKeyPath keyPath: String, | |
fromValue: Any?, | |
toValue: Any?)->[CABasicAnimation] { | |
let duration = CATransaction.animationDuration() | |
guard duration > 0 else { return [CABasicAnimation]() } | |
let alphaSwapDuration = min(LabelLayerFromToAlphaSwapAnimationDuration, 0.5 * duration) | |
let alphaPersistDuration = (duration - alphaSwapDuration) / 2.0 | |
let persistFromAlphaAnimation = CABasicAnimation(forKeyPath: keyPath, | |
fromValue: fromValue, | |
toValue: fromValue, | |
duration: alphaPersistDuration) | |
let swapAlphaAnimation = CABasicAnimation(forKeyPath: keyPath, | |
fromValue: fromValue, | |
toValue: toValue, | |
duration:alphaSwapDuration) | |
let persistToAlphaAnimation = CABasicAnimation(forKeyPath: keyPath, | |
fromValue: toValue, | |
toValue: toValue, | |
duration:alphaPersistDuration) | |
persistFromAlphaAnimation.beginTime = 0 | |
swapAlphaAnimation.beginTime = alphaPersistDuration | |
persistToAlphaAnimation.beginTime = alphaSwapDuration + alphaPersistDuration | |
return [persistFromAlphaAnimation, | |
swapAlphaAnimation, | |
persistToAlphaAnimation] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment