我在SwiftUI SegmentedPicker中遇到了问题,当我点击不同的段时,文字会跳动。
这是一个超级基本的问题,所以我不知道有什么选项可以调整这个问题。
struct ContentView : View {
@State private var selectorIndex = 0
@State private var numbers = ["One","Two","Three"]
var body: some View {
VStack {
Picker("Numbers", selection: $selectorIndex) {
ForEach(0 ..< numbers.count) { index in
Text(self.numbers[index]).tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
Text("Selected value is: \(numbers[selectorIndex])").padding()
}
}
}
试着把这个添加到Text中,尤其是对齐方式。
.frame(width: 222, height: 55, alignment: .leading)
编辑:
我正在用下面的代码在真实设备和各种模拟器上测试文本弹跳。
struct ContentView: View {
@State private var selectorIndex = 0
@State private var numbers = ["One","Two","Three"]
var body: some View {
VStack {
Picker("Numbers", selection: $selectorIndex) {
ForEach(0 ..< numbers.count) { index in
Text(self.numbers[index]).tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
Text("Selected value is: \(numbers[selectorIndex])")
.frame(width: 222, height: 55, alignment: .leading)
}
}
}