Created
June 6, 2019 02:58
-
-
Save aChase55/26c4d63e9f6edc0f8c50d790cf3d241b to your computer and use it in GitHub Desktop.
SwiftUI CGPoint Offset
This file contains 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
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