From f92d449e5a3a3052a42242a6def07dc1a1c8cf55 Mon Sep 17 00:00:00 2001 From: Ben Vogelzang Date: Sat, 10 Dec 2016 13:30:59 -0600 Subject: [PATCH] update thumbView shadow with animation. Closes #23 --- SevenSwitch.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SevenSwitch.swift b/SevenSwitch.swift index 13c7b26..d504345 100644 --- a/SevenSwitch.swift +++ b/SevenSwitch.swift @@ -308,6 +308,13 @@ import QuartzCore self.isAnimating = false }) + let shadowAnim = CABasicAnimation(keyPath: "shadowPath") + shadowAnim.duration = 0.3 + shadowAnim.fromValue = thumbView.layer.shadowPath + shadowAnim.toValue = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath + thumbView.layer.add(shadowAnim, forKey: "shadowPath") + thumbView.layer.shadowPath = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath + return true } @@ -446,6 +453,13 @@ import QuartzCore }, completion: { finished in self.isAnimating = false }) + + let shadowAnim = CABasicAnimation(keyPath: "shadowPath") + shadowAnim.duration = 0.3 + shadowAnim.fromValue = thumbView.layer.shadowPath + shadowAnim.toValue = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath + thumbView.layer.add(shadowAnim, forKey: "shadowPath") + thumbView.layer.shadowPath = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath } else { if self.isTracking { @@ -497,6 +511,13 @@ import QuartzCore }, completion: { finished in self.isAnimating = false }) + + let shadowAnim = CABasicAnimation(keyPath: "shadowPath") + shadowAnim.duration = 0.3 + shadowAnim.fromValue = thumbView.layer.shadowPath + shadowAnim.toValue = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath + thumbView.layer.add(shadowAnim, forKey: "shadowPath") + thumbView.layer.shadowPath = UIBezierPath(roundedRect: thumbView.bounds, cornerRadius: thumbView.layer.cornerRadius).cgPath } else { if (self.isTracking) {