View circularIndicator-1
let progressShape = CAShapeLayer()
let backgroundShape = CAShapeLayer()
var percent = 0.5
View CircleToRectangle-Step-14.swift
let color = UIColor(hue: 181/360.0 + CGFloat(Double(i)/500.0), saturation: 0.96, brightness: 0.88 , alpha: 1)
View CircleToRectangle-Step-13.swift
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)
}
}
View CircleToRectangle-Step-12.swift
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
View CircleToRectangle-Step-11.swift
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)
}
}
View CircleToRectangle-Step-10.swift
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)
View CircleToRectangle-Step-9.swift
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let shapeView = MutableShapeView(frame: view.frame)
view.addSubview(shapeView)
shapeView.animate()
}
View CircleToRectangle-Step-7.swift
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
View CircleToRectangle-Step-8.swift
for i in 0..<shapes.count {
shapes[i].animate(duration: 5.0, delay: Double(i+1)/6.0)
}
View CircleToRectangle-Step-6.swift
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)
}