Created
July 3, 2019 06:39
-
-
Save steveriggins/f9a81a83abee4082491c4fefa01a6cc3 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
// | |
// KnobView.swift | |
// | |
// Created by Steve Riggins on 6/30/19. | |
// Copyright © 2019 Steve Riggins. All rights reserved. | |
// | |
import SwiftUI | |
struct KnobView : View { | |
@State var degrees = 0.0 | |
var body: some View { | |
var dragGesture = DragGesture() | |
dragGesture.coordinateSpace = .global | |
return GeometryReader() { proxy in | |
ZStack { | |
Rectangle() | |
.fill(Color.red) | |
.gesture(dragGesture | |
.onChanged() { value in | |
// Calculate degrees using proxy.frame(in: .global)..... | |
} | |
) | |
Path() { path in | |
let f = proxy.frame(in: .local) | |
let centerX = f.width / 2.0 | |
// Vertical line | |
path.move(to: .init(x: centerX, y:f.maxY)) | |
path.addLine(to: .init(x: centerX, y:f.minY)) | |
// Left arrow arm | |
path.move(to: .init(x: centerX, y:f.minY)) | |
path.addLine(to: .init(x: centerX - 30, y:f.minY + 30)) | |
// Right arrow arm | |
path.move(to: .init(x: centerX, y:f.minY)) | |
path.addLine(to: .init(x: centerX + 30, y:f.minY + 30)) | |
} | |
.stroke() | |
} | |
.rotationEffect(.degrees(self.degrees)) | |
} | |
.frame(width: 100, height: 100) | |
} | |
} | |
#if DEBUG | |
struct KnobView_Previews : PreviewProvider { | |
static var previews: some View { | |
KnobView() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment