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

Use strongly-typed KeyPath in CALayer#animate() #20

Closed
sindresorhus opened this issue Mar 16, 2019 · 2 comments · Fixed by #28
Closed

Use strongly-typed KeyPath in CALayer#animate() #20

sindresorhus opened this issue Mar 16, 2019 · 2 comments · Fixed by #28
Labels
enhancement New feature or request 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted Extra attention is needed

Comments

@sindresorhus
Copy link
Owner

sindresorhus commented Mar 16, 2019

Issuehunt badges

In this extension:

extension CALayer {
// TODO: Find a way to use a strongly-typed KeyPath here.
// TODO: Accept NSColor instead of CGColor.
func animate(color: CGColor, keyPath: String, duration: Double) {
guard (value(forKey: keyPath) as! CGColor?) != color else {
return
}
let animation = CABasicAnimation(keyPath: keyPath)
animation.fromValue = value(forKey: keyPath)
animation.toValue = color
animation.duration = duration
animation.fillMode = .forwards
animation.isRemovedOnCompletion = false
add(animation, forKey: keyPath) { [weak self] _ in
self?.setValue(color, forKey: keyPath)
}
}
func add(_ animation: CAAnimation, forKey key: String?, completion: @escaping ((Bool) -> Void)) {
let animationDelegate = AnimationDelegate()
animationDelegate.didStopHandler = completion
animation.delegate = animationDelegate
add(animation, forKey: key)
}
}


IssueHunt Summary

fredyshox fredyshox has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@sindresorhus sindresorhus added enhancement New feature or request help wanted Extra attention is needed labels Mar 16, 2019
@IssueHuntBot
Copy link

@IssueHunt has funded $40.00 to this issue.


@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 10, 2019
@issuehunt-oss
Copy link

issuehunt-oss bot commented Dec 31, 2019

@sindresorhus has rewarded $36.00 to @fredyshox. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

@issuehunt-oss issuehunt-oss bot added 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt and removed 💵 Funded on Issuehunt This issue has been funded on Issuehunt labels Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants