简体   繁体   中英

Unable click on segmented picker in swift ui

I'm reusing one view for different scenarios. One is as modal window and second one is also modal but within navigation view.

My problem is that I can switching between options in picker only if view is as modal and not navigation view. If is within navigation view i'm not able to click on any option presented in picker.

 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)
    }

This is how the view looks where I'm not able to switch between options

无法切换

And here I can switch within same view but not opened as navigation view

可以切换

Update:

What I found out there is problem with.edgeIgorningSafeArea. When I removed this part of the code i'm able to switch on both scenarios but i want to keep switcher always on the top.

I have figure out by moving picker to the view where is NavigationView -> NavigationLink.navigationBarItems

And origin picker is under if statement and shows when is needed.

My question now is: if i have picker as navigationBarItems how I can handle events on that view?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM