Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Affine Transform #15

Open
Krisiacik opened this issue Dec 8, 2016 · 2 comments
Open

Affine Transform #15

Krisiacik opened this issue Dec 8, 2016 · 2 comments

Comments

@Krisiacik
Copy link

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)

}`

@AugustRush
Copy link
Owner

What‘s version of Swift did you used?

@Krisiacik
Copy link
Author

2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants