Shake Animation

func shakeAnimation() { let animation = CABasicAnimation(keyPath: "position") animation.duration = 0.07 animation.repeatCount = 3 animation.autoreverses = true animation.fromValue = NSValue(CGPoint: CGPointMake(self.center.x - 5, self.center.y)) animation.toValue = NSValue(CGPoint: CGPointMake(self.center.x + 5, self.center.y)) self.layer.addAnimation(animation, forKey: "position") }
Include this in an Extension of UIView

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.