Last active
July 17, 2016 19:22
-
-
Save marty-suzuki/ee1967e1afbd8327a1fcf73e32cdbbad 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
// based on this article. http://qiita.com/magickworx/items/9a8e6108db8134a8363a#comment-f7c2edf79151a38f4d9d | |
extension Double { | |
func toRadians() -> Double { | |
return self * Double(M_PI) / 180 | |
} | |
} | |
extension UIView { | |
private struct Const { | |
static let VibrateAnimationKey = "VibrateAnimationKey" | |
static let TransformRotationKeyPath = "transform.rotation" | |
} | |
func vibrated(vibrated: Bool) { | |
guard vibrated else { | |
layer.removeAnimationForKey(Const.VibrateAnimationKey) | |
return | |
} | |
let animation = CABasicAnimation(keyPath: Const.TransformRotationKeyPath) | |
animation.duration = 0.25 | |
animation.fromValue = 3.0.toRadians() | |
animation.toValue = -3.0.toRadians() | |
animation.repeatCount = .infinity | |
animation.autoreverses = true | |
layer.addAnimation(animation, forKey: Const.VibrateAnimationKey) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment