我有这个代码:
import SwiftUI
struct ContentView: View {
@State var show = false
var tools = [Tool("document.on.document"), Tool("document.on.clipboard")]
var body: some View {
HStack{
HStack {
ForEach(tools, id:\.id) { tool in
Button(action: {
print("toggle")
show.toggle()
}, label: {
Image(systemName:tool.name)
.imageScale(.large)
.foregroundStyle(.black.gradient)
.font(.system(size: 30))
})
.contentShape(Rectangle())
.popover(isPresented: $show, arrowEdge: .top) {
Color.red
.frame(width:400, height:400)
.onAppear{
print("popover show")
}
}
}
}
.padding()
}
.background(
RoundedRectangle(cornerSize: CGSize(width: 50,height: 50))
.fill(.red.opacity(0.5).gradient))
.padding()
}
}
#Preview {
ContentView()
}
struct Tool: Identifiable, Equatable {
let id = UUID()
let name:String
init(_ name: String) {
self.name = name
}
}
弹出窗口没有显示。我做了所有事情。
这是为什么?