Created
          July 28, 2018 13:41 
        
      - 
      
 - 
        
Save Alexander-Ignition/ce66bf02c55b1490381bd78b8a11918e to your computer and use it in GitHub Desktop.  
    Smart key path using with CABasicAnimation
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | class KeyPathAnimation<View, Value> { | |
| let basicAnimation: CABasicAnimation | |
| let keyPath: KeyPath<View, Value> | |
| init(keyPath: KeyPath<View, Value>) { | |
| self.keyPath = keyPath | |
| // https://github.com/apple/swift/blob/2844583d7f9d51ce5c4da7776e19f0aab6f2e3f6/stdlib/public/core/KeyPath.swift#L107 | |
| basicAnimation = CABasicAnimation(keyPath: keyPath._kvcKeyPathString) | |
| } | |
| // MARK: - CABasicAnimation | |
| var fromValue: Value? { | |
| get { | |
| return basicAnimation.fromValue as? Value | |
| } | |
| set { | |
| basicAnimation.fromValue = newValue | |
| } | |
| } | |
| var toValue: Value? { | |
| get { | |
| return basicAnimation.toValue as? Value | |
| } | |
| set { | |
| basicAnimation.toValue = newValue | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment