Textfield error animation

func shakeError() { let color = self.layer.borderColor let colorAnimation = CABasicAnimation(keyPath: "borderColor") colorAnimation.fromValue = UIColor.red.cgColor colorAnimation.toValue = color self.layer.borderColor = color let widthAnimation = CABasicAnimation(keyPath: "borderWidth") widthAnimation.fromValue = 1 widthAnimation.toValue = 2 widthAnimation.duration = 2 self.layer.borderWidth = 1 let shake = CABasicAnimation(keyPath: "position") shake.duration = 0.07 shake.repeatCount = 3 shake.autoreverses = true shake.fromValue = NSValue(cgPoint: CGPoint(x: self.center.x - 5, y: self.center.y)) shake.toValue = NSValue(cgPoint: CGPoint(x: self.center.x + 5, y: self.center.y)) let threeAnimations = CAAnimationGroup() threeAnimations.repeatCount = 3 threeAnimations.duration = 0.1 threeAnimations.autoreverses = true threeAnimations.animations = [colorAnimation, widthAnimation] threeAnimations.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) self.layer.add(threeAnimations, forKey: "color and width") }

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.