Skip to content

Instantly share code, notes, and snippets.

@aChase55
Created June 6, 2019 02:58
Show Gist options
  • Save aChase55/26c4d63e9f6edc0f8c50d790cf3d241b to your computer and use it in GitHub Desktop.
Save aChase55/26c4d63e9f6edc0f8c50d790cf3d241b to your computer and use it in GitHub Desktop.
SwiftUI CGPoint Offset
import SwiftUI
extension View {
public func offset(_ offset: CGPoint) -> Self.Modified<_OffsetEffect> {
self.offset(x: offset.x, y: offset.y)
}
}
struct ContentView : View {
@State var position: CGPoint = .zero
var body: some View {
Text("Hello World")
.offset(self.position)
.gesture(DragGesture()
.onChanged { self.position = $0.location }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment