AugustRush / Stellar

A fantastic Physical animation library for swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Affine Transform

Krisiacik opened this issue · comments

What are your thought about this?

Oftentimes I need to also animate affine scale. However this one is not supported by stellar. I wrote the following set of extensions to make it uniform with Stellar's syntax.

What are your thoughts? Do you see any systemic issue?

`struct CABasicAnimatedView {

let view: UIView
let animation: CABasicAnimation

}

extension UIView {

func makeAffineUniformScale(from from: CGFloat, to: CGFloat) -> CABasicAnimatedView {
    
    let animation = CABasicAnimation(keyPath: KeyPaths.Transform.scale)
    let animatedView = CABasicAnimatedView(view: self, animation: animation)
    
    animatedView.animation.fromValue = from
    animatedView.animation.toValue = to
    
    return animatedView
}

}

extension CABasicAnimatedView {

func duration(duration: NSTimeInterval) -> CABasicAnimatedView {
    
    self.animation.duration = duration
    
    return self
}

func timingFunction(timingFunction: CAMediaTimingFunction) -> CABasicAnimatedView {
    
    self.animation.timingFunction = timingFunction
    
    return self
}

func animate() {
    
    CATransaction.begin()
    self.view.layer.addAnimation(self.animation, forKey: nil)
    CATransaction.commit()
    
    self.view.transform = CGAffineTransformMakeUniformScale(self.animation.toValue as! CGFloat) }

}

func CGAffineTransformMakeUniformScale(scale: CGFloat) -> CGAffineTransform {

return CGAffineTransformMakeScale(scale, scale)

}`

What‘s version of Swift did you used?