Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created April 2, 2020 07:04
Show Gist options
  • Save wizard1066/301478edb4f5ea11478bf9008be0c5c9 to your computer and use it in GitHub Desktop.
Save wizard1066/301478edb4f5ea11478bf9008be0c5c9 to your computer and use it in GitHub Desktop.
abgwtp2
struct ContentView: View {
@State private var rect: CGPoint = CGPoint()
var body: some View {
ZStack {
Text("Hello World").background(InsideView(rect: $rect)).onTapGesture {
print("geometry ",self.rect)
}
Circle()
.fill(Color.yellow)
.frame(width: 10, height: 10, alignment: .center)
.position(rect)
}
}
}
struct InsideView: View {
@Binding var rect: CGPoint
var body: some View {
return GeometryReader { geometry in
Rectangle()
.frame(width: 0, height: 0, alignment: .leading)
.onAppear {
self.rect = geometry.frame(in: .global).origin
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment