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
for i in 0..<shapesCount { | |
let shape = MutableShapeLayer() | |
shape.setup(size: minimalSize + (step * CGFloat(i)), center: center, thickness: shapeWidth) | |
shapes.append(shape) | |
layer.addSublayer(shape) | |
} |
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
for i in 0..<shapes.count { | |
shapes[i].animate(duration: 5.0, delay: Double(i+1)/6.0) | |
} |
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
func animate(duration:TimeInterval, delay:TimeInterval) { | |
let animation = CAKeyframeAnimation(keyPath: "path") | |
animation.timingFunction = CAMediaTimingFunction(controlPoints: 0.66, 0.86, 0.11, 0.95) | |
animation.keyTimes = [0.0, 0.2, 0.6, 1.0] | |
animation.values = [circlePath, circlePath, rectangleShape, rectangleShape] | |
animation.beginTime = delay | |
animation.duration = duration | |
animation.fillMode = kCAFillModeForwards | |
animation.isRemovedOnCompletion = false | |
animation.repeatCount = Float.infinity |
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
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
let shapeView = MutableShapeView(frame: view.frame) | |
view.addSubview(shapeView) | |
shapeView.animate() | |
} |
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
let center = CGPoint(x: bounds.midX, y: bounds.midY) | |
var transform = CGAffineTransform.identity | |
transform = transform.translatedBy(x: center.x, y: center.y) | |
transform = transform.rotated(by: -CGFloat(M_PI_2 + M_PI_4)) | |
transform = transform.translatedBy(x: -center.x, y: -center.y) | |
circle.apply(transform) |
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
private func generateShapes() { | |
for i in 0..<shapesCount * 2 - 1 { | |
let shape = MutableShapeLayer() | |
shape.setup(size: minimalSize + ((step / 2.0) * CGFloat(i)), center: center, thickness: shapeWidth, color: (i % 2 == 0) ? UIColor.black : UIColor.white) | |
shapes.append(shape) | |
layer.insertSublayer(shape, at: 0) | |
} | |
} |
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
func setup(size:CGSize, center:CGPoint, thickness: CGFloat, color:UIColor) { | |
// 0 | |
frame = CGRect(origin: CGPoint.zero, size: size) | |
position = center | |
// 1 | |
path = circlePath | |
lineWidth = thickness | |
// 2 | |
strokeColor = color.cgColor | |
fillColor = UIColor.clear.cgColor |
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
func animate() { | |
if shapes.count == 0 { | |
generateShapes() | |
} | |
for i in 0..<shapes.count { | |
let delay = (i % 2 == 0) ? Double(i+1)/5.5 : Double(i+1)/5.505 | |
shapes[i].animate(duration: 5.0, delay: delay) | |
} | |
} |
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
let color = UIColor(hue: 181/360.0 + CGFloat(Double(i)/500.0), saturation: 0.96, brightness: 0.88 , alpha: 1) |
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
let progressShape = CAShapeLayer() | |
let backgroundShape = CAShapeLayer() | |
var percent = 0.5 |