【发布时间】:2021-03-19 06:43:23
【问题描述】:
我试图在右侧显示一个导航栏项目,我几乎成功了,但我在最后一刻卡住了我的导航右键在显示另一个视图后自动移动。请检查下面给出的我的代码和屏幕截图。
struct NvaigationButton: View {
@State private var showPopUpFlgInapp = false
var body: some View {
NavigationView {
ZStack {
ScrollView {
VStack {
Image("DemoImage1")
.resizable()
.aspectRatio(16/9, contentMode: .fit)
}
Spacer()
}
}
.navigationBarTitle("", displayMode: .inline)
.edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)
.navigationBarBackButtonHidden(true)
.navigationBarItems(leading:
Button(action: {
}) {
HStack {
Image( "BackButtonWithColor")
}},trailing: AnyView(self.trailingButton))
}
}
var trailingButton: some View {
HStack {
if showPopUpFlgInapp != true {
Button(action: {
showPopUpFlgInapp = true
}) {
HStack {
Image("ThreeDotsWithBckground")
}
}
}else if showPopUpFlgInapp == true {
showFlagInAppr(showPopUpFlgInapp:$showPopUpFlgInapp,action: {
showPopUpFlgInapp = false
})
}
}
}
}
struct showFlagInAppr: View {
@Binding var showPopUpFlgInapp: Bool
var action: () -> Void
var body: some View {
if showPopUpFlgInapp {
ZStack {
VStack(alignment:.leading,spacing:30) {
Button(action: action, label: {
Text("Flag as inappropriate")
})
}
}.padding(20)
.background(Color.init(UIColor.init(displayP3Red: 29/255, green: 33/255, blue: 33/255, alpha: 1.0)))
.foregroundColor(.white)
.cornerRadius(10)
}
}
}
【问题讨论】:
-
这肯定是一个错误,你的代码没有问题。
标签: button swiftui navigation uinavigationbar