jim*_*jon 1 swiftui navigationlink
我有以下导航链接:
NavigationLink(destination:
TrendSlider(
title: .constant(title),
col: .constant(self.dataModel.queryColumnSeasonWinPercentageTeam1),
opIndx: self.$dataModel.seasonWinPercentageTeam1OperatorIndxValue,
val: self.$dataModel.seasonWinPercentageTeam1SliderValue,
lBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.first!) ,
uBound: .constant(self.dataModel.seasonWinPercentageTeam1Values.last!),
lRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderLowerValue ,
uRange: self.$dataModel.seasonWinPercentageTeam1RangeSliderUpperValue,
step: .constant(1.0),
displayReadableQuery: $readableQuery
)) {
HStack {
if readableQuery.hasSuffix("IS ANY") {
Text(title)
Spacer()
Text("IS ANY").foregroundColor(Color("TPLightGrey"))
}else{
Text(readableQuery).foregroundColor(Color("TPOrange"))
}
}
}.simultaneousGesture(TapGesture().onEnded{
sendViewSelectionEvent(name: self.title, referral: "Game")
})
Run Code Online (Sandbox Code Playgroud)
如果我离开“.simultaneousGesture...”,则点击 Text 元素不会触发 NavigationLink 操作,但该行的其余部分确实有效。
如果我删除 .simultaneousGesture,则可以再次点击该行。
漏洞?
添加.simultaneousGesture(:)呼叫是在 的标签上创建点击手势识别器NavigationLink,而不是在行本身上。关于手势识别器的两个事实解释了观察到的行为。
NavigationLink实际上位于列表/表单行上方(见图),这意味着它现在将在到达列表/表单行之前拦截任何点击。因此,当您点击其中一个文本视图时,点击由TapGesure.onEnded()闭包处理。但是当您点击中间的空间时,点击“通过”并由列表/表单行上的识别器处理,触发NavigationView序列。
因此,SwiftUI 设计决策,而不是错误。目前,List/Form不是为了在保持导航功能的同时识别自定义手势而构建的。如果您有这种行为的用例,请提交一些反馈,也许我们会在明年看到它。
| 归档时间: |
|
| 查看次数: |
573 次 |
| 最近记录: |