无法在快速用户界面中点击分段选择器

问题描述 投票:0回答:1

我将一个视图用于不同的场景。一种是模态窗口,第二种是模态窗口,但在导航视图中。

我的问题是,仅当视图是模式视图而不是导航视图时,才可以在选择器中的选项之间切换。如果在导航视图中,则无法单击选择器中显示的任何选项。

 ZStack {
        Color("my-orange").edgesIgnoringSafeArea(.top)

        VStack(alignment: .leading) {
            if !self.picture {
                Image("van")
                    .resizable()
                    .frame(width: UIScreen.main.bounds.width, height: 275)
                    .padding(.leading)
            }

            Picker(selection: $langauge, label: Text("Test")) {
                ForEach(0..<contentLanguages.languages.count, id:\.self) { index  in
                    Group {
                        if self.contentLanguages.languages[index].isOn {
                            Text(self.contentLanguages.languages[index].country).tag(index)
                            .foregroundColor(.white)
                        }
                    }
                }

            }.pickerStyle(SegmentedPickerStyle())
                .padding([.leading, .trailing], 60)
                .padding([.top, .bottom])
                .background(Color("my-orange"))

            Spacer()
            TabBar(index: $index)
                .offset(y: self.picture ? -30 : 0)
        }.edgesIgnoringSafeArea(.all)
    }

这是无法在选项之间切换的视图的外观

Not able to switch

并且我可以在同一视图内切换,但不能以导航视图打开

Able to switch

更新:

我发现.edgeIgorningSafeArea存在问题。当我删除了这部分代码时,我可以在两种情况下都打开,但我想始终将切换器始终放在顶部。

ios swiftui swift5 picker
1个回答
0
投票

我已经通过将选择器移动到NavigationView-> NavigationLink.navigationBarItems所在的视图中找出了>>

并且起点选择器在if语句下,并显示何时需要。

我现在的问题是:如果我将选择器用作navigationBarItems,如何处理该视图上的事件?

© www.soinside.com 2019 - 2024. All rights reserved.