Skip to content

Instantly share code, notes, and snippets.

@Arrlindii
Created December 6, 2019 22:40
Show Gist options
  • Select an option

  • Save Arrlindii/f3c144263f59c41c47b67d61260ed053 to your computer and use it in GitHub Desktop.

Select an option

Save Arrlindii/f3c144263f59c41c47b67d61260ed053 to your computer and use it in GitHub Desktop.
private struct RingHead: Shape {
var endAngle: Angle
let ringWidth: CGFloat
var animatableData: Double {
get {return endAngle.radians}
set {endAngle = Angle(radians: newValue)}
}
func path(in rect: CGRect) -> Path {
var path = Path()
let radius = (min(rect.width, rect.height) - ringWidth)/2
let center = CGPoint(x: rect.midX - ringWidth/2, y: rect.midY - ringWidth/2)
let point = getRotationPoint(angle: endAngle.radians, radius: radius, center: center)
let frame = CGRect(x: point.x, y: point.y, width: ringWidth, height: ringWidth)
path.addRoundedRect(in: frame, cornerSize: frame.size)
return path
}
func getRotationPoint(angle: Double, radius: CGFloat, center: CGPoint) -> CGPoint {
return CGPoint(x: center.x + CGFloat(cos(angle)) * radius,
y: center.y + CGFloat(sin(angle)) * radius)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment