Created
April 2, 2020 07:04
-
-
Save wizard1066/301478edb4f5ea11478bf9008be0c5c9 to your computer and use it in GitHub Desktop.
abgwtp2
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
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