我尝试重新实现我正在使用的 SegmentedControlers,因为它们在 Xcode 11 beta 5 中已被弃用。这花了一段时间,但我得到了我想要的外观。但是,当我用 onTapGesture() 替换 tapAction 时,选择器停止工作。
下面的代码显示了问题。注释掉 pickerStyle 会得到一个与 onTapGesture() 一起工作的轮子选择器
import SwiftUI
var oneSelected = false
struct ContentView: View {
@State var sel = 0
var body: some View {
VStack {
Picker("Test", selection: $sel) {
Text("A").tag(0)
Text("B").tag(1)
Text("C").tag(2)
}
.pickerStyle(SegmentedPickerStyle())
Picker("Test", selection: $sel) {
Text("A").tag(0)
Text("B").tag(1)
Text("C").tag(2)
}
.pickerStyle(SegmentedPickerStyle())
.onTapGesture(perform: {
oneSelected = (self.sel == 1)
})
Text("Selected: \(sel)")
}
}
}
#if DEBUG
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
#endif
我希望 Picker().pickerStyle(SegmentedPickerStyle()) 应该像 SegmentedController() 一样工作。