Har*_*kar 10 datepicker swiftui
下面的代码在iOS 17.0.1中运行良好,但在最新的更新中,当我们点击17.1 DatePicker 时,它不会打开。
经过几次尝试,我发现长按大约 2-3 秒,它会打开日期选择器。
这个问题有什么解决办法吗?如何仅在点击时打开?
VStack(alignment: .leading){
Text("Date".localized())
.applyFont(style: .Medium, size: 18)
.foregroundColor(Colors.grayLight)
HStack{
let lastYear = Calendar.current.date(byAdding: .year, value: -1, to: Date()) ?? Date()
if let date = checkLowerBound(){
DatePicker("",selection:$selectedDate, in: date...Date(), displayedComponents: [.date])
.frame(width: 100)
}else{
DatePicker("",selection:$selectedDate, in: lowestDate...Date(), displayedComponents: [.date])
.frame(width: 100)
}
Spacer()
}
.padding(.horizontal, 10)
}
.cardProperty()
.allowsHitTesting(!(eventTransaction != nil && eventTransaction?.by != UserDefaults.userID))
Run Code Online (Sandbox Code Playgroud)
小智 20
看起来,如果 a TapGestureis 处理层次结构中较高的某个位置,从 17.1 开始, withDatePicker将displayedComponents: .date遵循它,并且不会触发其自己的行为。
simultaneousGesture似乎没有帮助。然而,我找到了一个 hacky 解决方案。通过DatePicker用所需的 Count 包装自己的 TapGesture 处理程序,只要未满足计数,就不会触发此错误行为。
最小可行的触发代码及其解决方案:
struct ContentView: View {
@State private var date = Date()
var body: some View {
VStack {
DatePicker(
"Foo",
selection: $date,
displayedComponents: .date
)
.onTapGesture(count: 99, perform: {
// overrides tap gesture to fix ios 17.1 bug
})
}
.onTapGesture {
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到了类似的问题并找到了解决方案。就我而言,当我使用包含我的内容的onTapGesture整个内容ZStack并调用view.endEditing(). 此问题在 17.1 版本中出现,但在早期版本中没有出现。
| 归档时间: |
|
| 查看次数: |
1564 次 |
| 最近记录: |