【发布时间】:2021-01-14 01:02:11
【问题描述】:
我希望 SwiftUI 可以了解我在哪里点击我的应用程序,因此我为我的视图提供了 .onTapGesture 可能性,在此代码中,视图大于其父视图,但我可以使用剪辑解决问题,问题得到解决视觉上,但在代码 SwiftUI 中看到原始大小的 Rec,我想知道这种错误行为是否是 SwiftUI 中的错误,或者我们用一些魔术代码解决它的代码?谢谢大家。
gif:
struct ContentView: View {
var body: some View {
ZStack {
Color.white.ignoresSafeArea()
.onTapGesture { print("you tapped on Screen!") }
Circle()
.fill(Color.red)
.frame(width: 300, height: 300, alignment: .center)
.overlay(
Rectangle()
.fill(Color.yellow)
.frame(width: 100, height: UIScreen.main.bounds.height, alignment: .center)
.onTapGesture { print("you tapped on Rectangle!") }
)
.clipShape(Circle())
.onTapGesture { print("you tapped on Circle!") }
}
}
}
【问题讨论】:
标签: swiftui