SwiftUI - picker is having freezing when selecting after keyboard is up

╄→尐↘猪︶ㄣ 提交于 2021-01-28 09:51:45

问题


I have a picker:

Section(header: Text("About you")) {
    TextField("About you", text: $profileViewModel.bio)
    Picker(selection: $profileViewModel.education,
          label: Text("Education Level")) {
           ForEach(Education.levels, id: \.self) { level in
                 Text(level).tag(level)
           }
       }
     TextField("Occupation", text: $profileViewModel.occupation)
 }

When I click on the text field, the keyboard appears, which is fine, but when i click on the picker it takes me to the new screen to pick the value and return to the form. This works fine on my simulator (iPhone 11 Pro Max):

Version 11.6 (921.9.1)
SimulatorKit 581.9.1
CoreSimulator 704.12.2 

But when I test this on my real device iPhone X - v13.5.1 when i click on the picker after the textfield (keyboard is visible) the app crashes. Im not sure this is a bug?

I then put a ontapGesture to the picker to hide the keyboard:

Picker(selection: $profileViewModel.education,
     label: Text("Education Level")) {
     ForEach(Education.levels, id: \.self) { level in
         Text(level).tag(level)
     }
}.onTapGesture {
    self.hideKeyboard()
}

This works sometime, but sometimes still crashes, Even when i connect my device to Xcode and try to get logs, I get no error, the app just freezes?


回答1:


It looks like there is a bug with the spring animation, after removing the spring animation it all works fine



来源:https://stackoverflow.com/questions/63449700/swiftui-picker-is-having-freezing-when-selecting-after-keyboard-is-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!