swiftui自定义弹窗,弹出指定消息。
·
swiftui自定义弹窗,弹出指定消息。
也可以理解为页面的跳转。
再次点击弹窗中的内容时候消失弹窗的内容。


body部分代码如下。
struct ContentView : View {
var body: some View {
return ZStack{
//自定义窗口弹窗
Button("Show自定义窗口") {
// self.showingPayModel = true
self.isPositionOut()
}
if $showingPayModel.wrappedValue{
ZStack{
Color(.blue).edgesIgnoringSafeArea(.all)
VStack(spacing:0.5){
//水平显示时间与费用
HStack{
HStack{
Image(systemName: "alarm")
Text("停车时间:51分")
}//HStack
.padding(5)
HStack{
Image(systemName: "dollarsign.circle")
Text("停车费用5元")
}//HStack
.padding(5)
}//HStack
// .offset(y:-130)
.font(Font.system(size:16, design: .default))
//设置黑色的下划线
HStack{
Capsule().fill(Color.black)
.frame(width:262,height: 1.6)
}
//收费规则显示
VStack(alignment: .leading){
Text("收费标准:5元/1小时,15分钟内免费,不足1小时按1小时计费,每24小时封顶80元,总封顶299元。")
}//VStack rules
.padding(10)
.font(Font.system(size:14, design: .default))
//水平显示取消按钮与 支付按钮
HStack{
Button("取消"){
self.showingPayModel = false
}
.foregroundColor(.red)
.accentColor(.red)
.frame(minWidth: 110, idealWidth: 110, maxWidth: 110,
minHeight: 40,idealHeight: 40,maxHeight: 40,
alignment: .center)
// .background(Color.purple)
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 28.0/2, style: .continuous)
.stroke(Color(.gray), lineWidth: 0.5)
)
.padding(10)
Spacer()
Button("支付"){
self.showingPayModel = false
}
.frame(minWidth: 110, idealWidth: 110, maxWidth: 110,
minHeight: 40,idealHeight: 40,maxHeight: 40,
alignment: .center)
// .background(Color.purple)
.cornerRadius(10)
.overlay(
RoundedRectangle(cornerRadius: 28.0/2, style: .continuous)
.stroke(Color(.gray), lineWidth: 0.5)
)
.padding(10)
}//HStack /button -> /submit /cancel
.padding(5)
// .background(Color.orange)
}//VStack
.frame(minWidth: 280, idealWidth: 280, maxWidth: 320,
minHeight: 160,idealHeight: 160,maxHeight: 200,
alignment: .center)
.background(Color.white)
.cornerRadius(20)
.shadow(color: Color.gray, radius: 6, x: 0, y: 0)
}//ZStack
}
}//ZStack
}//bodyView
//定义相机位置的参数
@State private var positionOfCamera = "1.203242"
//定义是否显示收费弹窗
@State private var showingPayModel = false
// 定义入口处检测函数
func isPositionOut(){
if positionOfCamera == "1.203242" {
showingPayModel = true
}
}
}
更多推荐
所有评论(0)