Skip to content

Instantly share code, notes, and snippets.

@allfinlir
Created January 17, 2023 20:20
Show Gist options
  • Save allfinlir/093c54bd7c7ee58eb9a0841fedb5ae51 to your computer and use it in GitHub Desktop.
Save allfinlir/093c54bd7c7ee58eb9a0841fedb5ae51 to your computer and use it in GitHub Desktop.
import SwiftUI
struct AppleLoadingCursor: View {
@State private var showView: Bool = false
@State private var rotateCursor: Bool = false
var body: some View {
VStack {
ZStack {
if showView {
ZStack {
AppleCursor()
.foregroundColor(.orange)
AppleCursor()
.foregroundColor(.red)
.rotationEffect(Angle(degrees: 60))
AppleCursor()
.foregroundColor(.purple)
.rotationEffect(Angle(degrees: 120))
AppleCursor()
.foregroundColor(.blue)
.rotationEffect(Angle(degrees: 180))
AppleCursor()
.foregroundColor(.green)
.rotationEffect(Angle(degrees: 240))
AppleCursor()
.foregroundColor(.yellow)
.rotationEffect(Angle(degrees: 300))
AppleCursorLastPiece()
.foregroundColor(.orange)
}
//.frame(width: 300, height: 300)
} else {
ZStack {
Image(systemName: "cursorarrow")
.font(.largeTitle)
.opacity(showView ? 0 : 1)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.rotationEffect(Angle(degrees: rotateCursor ? 1080 : 0))
// .animation(.linear(duration: 3).repeatForever(autoreverses: false), value: rotateCursor)
Button(action: {
// showView = true
// rotateCursor = true
withAnimation(.linear(duration: 0.5)) {
showView = true
}
withAnimation(.linear(duration: 3.5).repeatForever(autoreverses: false)) {
rotateCursor = true
}
}, label: {
Text("Loading Cursor")
.font(.largeTitle)
})
}
}
}
struct AppleLoadingCursor_Previews: PreviewProvider {
static var previews: some View {
AppleLoadingCursor()
}
}
struct AppleCursor: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.midX, startAngle: Angle(degrees: -5), endAngle: Angle(degrees: 235), clockwise: true)
path.addQuadCurve(to: CGPoint(x: rect.midX, y: rect.midY), control: CGPoint(x: rect.midX + (rect.midX * 0.3), y: rect.midY + (rect.midY * -0.35)))
}
}
}
struct AppleCursorLastPiece: Shape {
func path(in rect: CGRect) -> Path {
Path { path in
path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.midX, startAngle: Angle(degrees: -65), endAngle: Angle(degrees: 235), clockwise: true)
path.addQuadCurve(to: CGPoint(x: rect.midX, y: rect.midY), control: CGPoint(x: rect.midX + (rect.midX * 0.3), y: rect.midY + (rect.midY * -0.35)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment