SwiftUI - 选择器在键盘启动后选择时冻结 [英] SwiftUI - picker is having freezing when selecting after keyboard is up

查看:27
本文介绍了SwiftUI - 选择器在键盘启动后选择时冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择器:

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

当我单击文本字段时,会出现键盘,这很好,但是当我单击选择器时,它会将我带到新屏幕以选择值并返回到表单.这在我的模拟器(iPhone 11 Pro Max)上运行良好:

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 

但是当我在我的真实设备 iPhone X - v13.5.1 上测试这个时,当我在文本字段(键盘可见)后单击选择器时,应用程序崩溃了.我不确定这是一个错误吗?

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?

然后我将 ontapGesture 放在选择器上以隐藏键盘:

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

这有时有效,但有时仍会崩溃,即使我将设备连接到 Xcode 并尝试获取日志,我也没有收到任何错误,应用程序只是死机?

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?

推荐答案

spring 动画好像有问题,去掉spring 动画后一切正常

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

这篇关于SwiftUI - 选择器在键盘启动后选择时冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆