我想知道鼠标指针相对于应用程序窗口的当前位置(xy),并将其提供给状态变量
positionME
。为什么会抛出错误?
Value of type 'GeometryProxy' has no member 'location'
Cannot convert value of type '()' to expected argument type '(() -> Void)?'
struct ContentView: View {
@State private var positionME: CGPoint?
var body: some View {
VStack {
GeometryReader { gp in
Rectangle()
.fill(.green)
.frame(width: 100, height: 100)
.onAppear(perform: positionME = $0.location)
}
.padding()
}}
}