Created
December 6, 2019 22:40
-
-
Save Arrlindii/f3c144263f59c41c47b67d61260ed053 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
| 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