【发布时间】:2021-10-08 09:32:43
【问题描述】:
我已经从开发应用程序从 Obj-C 切换到 swiftUI。 我有一个按钮,当点击它应该显示弹出视图。按照此链接显示弹出窗口https://blog.techchee.com/how-to-create-a-pop-up-view-with-swiftui/
但单击按钮时不会出现弹出窗口。这是我的代码
struct Location: View {
var body: some View {
ZStack{
Button(action: {
popUpView()
}, label: {
Text("Select Location")
.frame(minWidth: 0, maxWidth: 500)
.padding()
.background(Color.clear)
.foregroundColor(Color.black)
.font(.custom("Open Sans", size: 18))
.overlay(
RoundedRectangle(cornerRadius: 10)
.stroke(Color.gray, lineWidth: 2)
)
})
}
}
private let choices = ["Apple", "Orange", "Papaya", "Grape", "Star Fruit", "Strawberries", "Raspberries", "Blueberries"].sorted()
func popUpView()-> some View {
VStack (spacing : 10) {
Text("Choices Of Fruits").font(Font.custom("Avenir-Black", size: 18.0))
.position(x:100 , y:400)
List(choices, id:\.self) { Text($0) }
Button(action: {
withAnimation {
}
}, label: {
Text("Close")
})
}
.padding()
.frame(width: 240, height: 300)
.background(Color.white)
.cornerRadius(20)
.shadow(radius: 20 )
}
}
请帮忙看看哪里出错了?
【问题讨论】: