繁体   English   中英

XCode13 和 iOS15 和 iPadOS15 上的 swiftUI 表单错误

[英]swiftUI form bug on XCode13 and iOS15 and iPadOS15

我正在 Xcode 12 上构建一个表单并使用 iOS 14,一切都按预期工作。 但是在切换到 13 和 iOS 15 后,单元格的高度不一致,甚至在屏幕外滚动时也会发生变化,就像它们是可重复使用的表格单元格一样。

例如,我有这个代码: *** 编辑:我更改了下面的代码以拥有该页面上当前的所有内容。

    Struct EvalViewMHx: View {
    var body: some View {
    VStack {
        
        Form {
            
            Label(
                title: {
                    Text("Demographics & Medical History")
                        .font(.title)
                        .foregroundColor(.white)
                        .padding()
                },
                icon: {
                    Image(systemName: "heart.text.square.fill")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .foregroundColor(.white)
                    
                })
                .listRowBackground(Color.blue)
                .frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
            
            
            Section(header: Text("Demographics")) {
                demographicsView(nameText: $nameText, DOB: $DOB, height: $height, weight: $weight)
            }
            
            
            
            Section(header: Text("Medical History")) {
                
                VStack {
                    HStack {
                        Text("When did you get hurt?")
                        
                            .padding()
                        
                        Spacer()
                        
                        Toggle("", isOn: $doesNotKnowInjuryDate)
                            .frame(width: 35)
                            .padding(.horizontal)
                        
                        Text("I don't know")
                            .fontWeight(!doesNotKnowInjuryDate ? .regular : .bold)
                            .padding(.leading)
                        
                    }
                    
                    if !doesNotKnowInjuryDate {
                        DatePicker("Injury Date", selection: $injuryDate, displayedComponents: [.date])
                            .foregroundColor(Color(UIColor.systemGray3))
                            .padding()
                    }
                    
                }
                .frame(minWidth: .zero, idealWidth: .infinity, maxWidth: .infinity, minHeight: 150, idealHeight: 150, maxHeight: 150, alignment: .center)
                
                VStack(alignment: .leading) {
                    
                    HStack {
                        Text("Where is your injury?")
                        
                        Spacer()
                        
                        Text("Right")
                            .fontWeight(isInjuryOnRightSide ? .regular : .bold)
                        
                        Toggle("", isOn: $isInjuryOnRightSide)
                            .toggleStyle(SwitchToggleStyle(tint: Color(UIColor.systemGray5)))
                            .frame(width: 35)
                            .padding(.horizontal)
                        
                        Text("Left")
                            .fontWeight(!isInjuryOnRightSide ? .regular : .bold)
                            .padding(.leading)
                    }
                    .zIndex(2.0)
                    
                    
                    
                    Picker(selection: $injuryLocation, label: Text(""), content: {
                        ForEach(injuryLocations, id: \.self) { location in
                            Text(location)
                        }
                    })
                    .pickerStyle(WheelPickerStyle())
                    .frame(minWidth: .zero, idealWidth: .infinity, maxWidth: .infinity, minHeight: 100, idealHeight: 100, maxHeight: 100, alignment: .center)
                    .zIndex(1.0)
                    .padding()
                    
                    
                    
                }
                .padding()
                
                VStack(alignment: .leading) {
                    Text("How did you get hurt? (Method of Injury)")
                        .padding()
                    
                    TextEditor(text: $MOI)
                        .frame(height: 150)
                        .background(Color(UIColor.systemGray5).opacity(0.75))
                        .cornerRadius(15)
                    
                }
                .frame(minWidth: .zero, idealWidth: .infinity, maxWidth: .infinity, minHeight: 200, idealHeight: 200, maxHeight: 200, alignment: .center)
                .padding()
                
                if injuryLocation != "Lower Back" && injuryLocation != "Upper Back" && injuryLocation != "Head / Neck" && injuryLocation != "Chest" {
                    
                    VStack {
                        pastInjuryHistory(injuryLocation: $injuryLocation, hasHadSameSideInjury: $hasHadSameSideInjury, hasHadOppositeSideInjury: $hasHadOppositeSideInjury, isSameSide: true)
                        
                        pastInjuryHistory(injuryLocation: $injuryLocation, hasHadSameSideInjury: $hasHadSameSideInjury, hasHadOppositeSideInjury: $hasHadOppositeSideInjury, isSameSide: false)
                        
                    }
                }
            }
        }
    }
}
    }

(在下图中,您还会在顶部看到一些按钮,它们只是水平滚动视图中的矩形。然后,上面的代码就放在选项卡视图中的下方,如下所示:)

                        TabView(selection: $activeTab) {
            
            EvalViewMHx()
                .tag(1)
            
            EvalObjectiveView()
                .tag(2)
            
            viewThree(activeTab: $activeTab)
                .tag(3)
            
            viewFour(activeTab: $activeTab)
                .tag(4)
            
        }
        .tabViewStyle(PageTabViewStyle())
        .onChange(of: activeTab, perform: { value in
            print(activeTab)
        })
        .animation(.default)

并且输出显示其中一个单元格具有完全不同的高度。

在此处输入图片说明

更奇怪的是,另一个部分有一个高度为 0 的单元格,但仍然显示位于其余单元格上的文本字段。 我有一个选择器视图也在这些单元格中,并将选择器样式放置到

.pickerStyle(InlinePickerStyle())

将单元格扩展到大于 iPad 屏幕尺寸,并且不会像在以前的版本中那样将其放入轮子中。

这些错误是我应该耐心修复的,还是我可以做些什么来修复它并继续我的项目?

正在努力解决同样的问题。 结果是 .animation 导致了这个问题,因为它自 iOS 15 以来已被弃用。删除该行为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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