简体   繁体   English

iOS 14.2 datePicker 坏了吗?

[英]is iOS 14.2 datePicker broken?

I am encountering a problem with DatePickers() view in iOS 14.2 when they are in Forms when the keyboard opens.我在 iOS 14.2 中的 DatePickers() 视图中遇到问题,当键盘打开时它们在 Forms 中。 Can somebody confirm that it is a swiftUI Bug ?有人可以确认这是一个 swiftUI 错误吗? I am quite new to iOS dev.我对 iOS 开发人员很陌生。

Here is my view :这是我的观点:

struct TestView: View {
    @State private var test = Date()
    var body: some View {
        return
            NavigationView {
                VStack {
                    HStack {
                        Spacer()
                        Capsule()
                            .fill(Color.secondary)
                            .frame(width: 80, height: 5, alignment: .center)
                        Spacer()
                    }.padding()
                    Form {
                        Section(header: Text("sectionTitle")) {
                            Group {
                                Text("something")
                                Text("To")
                                Text("Fill")
                                Text("The")
                                Text("View")
                                Text("Vertically")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")

                            }
                            Group {
                                Text("something")
                                Text("To")
                                Text("Fill")
                                Text("The")
                                Text("View")
                                Text("Vertically")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")
                                Text("Bla")

                            }
                            DatePicker("a label",
                                       selection: $test,
                                       displayedComponents: .hourAndMinute)
                        }
                    }
                    .padding()
                }
        
            }
    }
}

What is happening is : When I click on the datePicker -> the picker is showed in a modal (normal behaviour in iOS 14) but when editing it the keyboard shows and disappears immediately, closes the modal.发生的事情是:当我单击 datePicker -> 选择器显示在模式中(iOS 14 中的正常行为),但是在编辑它时,键盘会立即显示并消失,关闭模式。 Making the Picker unusable.使选择器无法使用。

This does not happen if I remove the Form view OR if I remove some of the texts field.如果我删除表单视图或删除某些文本字段,则不会发生这种情况。

I use this view in a sheet() on iOS 14.2 iPhone SE 2020 simulator and real device.我在 iOS 14.2 iPhone SE 2020 模拟器和真实设备上的 sheet() 中使用此视图。 Work properly on ios13 (with wheels).在 ios13(带轮子)上正常工作。

Thanks谢谢

This looks like a bug.这看起来像一个错误。 Based on the print out "Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view", it seems that when you click onto the DatePicker, it's having trouble figuring out the full size of the Form (possibly because it's so close to the bottom of the screen?)根据打印输出“检测到约束模糊地建议表格视图单元格的内容视图的高度为零的情况”,似乎当您单击 DatePicker 时,它无法确定表单的完整大小(可能是因为它离屏幕底部这么近?)

Personally, I would remove the DatePicker from the form to ensure users ever encounter this.就个人而言,我会从表单中删除 DatePicker,以确保用户遇到过这种情况。 But if you need to use the Form, work arounds I found:但是如果你需要使用表单,我发现的解决方法:

  1. Add one of the Groups or additional content after the DatePicker在 DatePicker 之后添加组之一或其他内容
  2. Add a Spacer(minLength: 200) after the DatePicker在 DatePicker 之后添加一个 Spacer(minLength: 200)
  3. Set the frame's height of the Form设置窗体的框架高度

Consider to use GraphicalDatePickerStyle instead of default style.考虑使用GraphicalDatePickerStyle而不是默认样式。

HStack {
    Text("a Label")
    Spacer()
    DatePicker("", selection: $test, displayedComponents: .hourAndMinute)
        .datePickerStyle(GraphicalDatePickerStyle())
}

I think this is an Apple bug, I'm using the picker this way我认为这是一个 Apple 错误,我正在以这种方式使用选择器

Form {
     Section {
        DatePicker(self.label, selection: self.value)
     }
}

and still I have this error我仍然有这个错误

2020-11-29 21:11:08.171127+0100 Budgetify[85909:3309604] [Warning] Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a table view cell's content view. 2020-11-29 21:11:08.171127+0100 Budgetify[85909:3309604] [警告] 仅警告一次:检测到约束模糊地建议表格视图单元格内容视图高度为零的情况。 We're considering the collapse unintentional and using standard height instead.我们正在考虑无意识的坍塌并使用标准高度。 Cell: <SwiftUI.ListCoreCellHost: 0x7ffdbc08f800;单元格:<SwiftUI.ListCoreCellHost:0x7ffdbc08f800; baseClass = UITableViewCell; baseClass = UITableViewCell; frame = (0 123; 788 44);框架 = (0 123; 788 44); autoresize = W;自动调整大小 = W; layer = <CALayer: 0x60000223b960>>层 = <CALayer: 0x60000223b960>>

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

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