Created
April 10, 2018 07:37
-
-
Save victorchee/4273e5877db71916fbb1d9e042ddec39 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@IBAction func buttonTapped(_ sender: UIButton) { | |
let pathFrame = CGRect(x: -sender.bounds.midX, y: -sender.bounds.midY, width: sender.bounds.width, height: sender.bounds.height) | |
let path = UIBezierPath(roundedRect: pathFrame, cornerRadius: sender.layer.cornerRadius) | |
let shapePosition = self.view.convert(sender.center, from: self.view) | |
let circleShape = CAShapeLayer() | |
circleShape.path = path.cgPath | |
circleShape.position = shapePosition | |
circleShape.fillColor = UIColor.clear.cgColor | |
circleShape.opacity = 0 | |
circleShape.strokeColor = UIColor.red.cgColor | |
circleShape.lineWidth = 2 | |
self.view.layer.addSublayer(circleShape) | |
let scaleAnimation = CABasicAnimation(keyPath: "transform.scale") | |
scaleAnimation.fromValue = NSValue(caTransform3D: CATransform3DIdentity) | |
scaleAnimation.toValue = NSValue(caTransform3D: CATransform3DMakeScale(2.5, 2.5, 1)) | |
let alphaAnimation = CABasicAnimation(keyPath: "opacity") | |
alphaAnimation.fromValue = 1 | |
alphaAnimation.toValue = 0 | |
let animationGroup = CAAnimationGroup() | |
animationGroup.animations = [scaleAnimation, alphaAnimation] | |
animationGroup.duration = 0.5 | |
animationGroup.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) | |
circleShape.add(animationGroup, forKey: nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment