首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XCode13、iOS15和iPadOS15上的swiftUI窗体错误

XCode13、iOS15和iPadOS15上的swiftUI窗体错误
EN

Stack Overflow用户
提问于 2021-09-24 21:10:17
回答 1查看 543关注 0票数 2

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

例如,我有这样的代码:* EDIT:我更改了下面的代码,以包含该页面上当前的所有内容。

代码语言:javascript
复制
    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)
                        
                    }
                }
            }
        }
    }
}
    }

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

代码语言:javascript
复制
                        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放到

代码语言:javascript
复制
.pickerStyle(InlinePickerStyle())

将单元格扩展到比iPad屏幕更大的尺寸,而不是像以前的版本那样放在滚轮中。

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

EN

回答 1

Stack Overflow用户

发布于 2021-11-23 09:57:58

也在努力解决同样的问题。结果是.animation导致了这个问题,因为它从iOS 15开始就被弃用了。删除这行代码就解决了这个问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69321132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档