【发布时间】:2020-03-29 09:15:47
【问题描述】:
在更改视图中的一些其他数据后刷新视图时,我在选定的分段控件段中遇到以下文本动画:
这是一个错误/功能还是有办法消除这种行为?
这是重现效果的代码:
import SwiftUI
struct ContentView: View {
let colorNames1 = ["Red", "Green", "Blue"]
@State private var color1 = 0
let colorNames2 = ["Yellow", "Purple", "Orange"]
@State private var color2 = 0
var body: some View {
VStack {
VStack {
Picker(selection: $color1, label: Text("Color")) {
ForEach(0..<3, id: \.self) { index in
Text(self.colorNames1[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
Text("Color 1: \(color1)")
}
.padding()
VStack {
Picker(selection: $color2, label: Text("Color")) {
ForEach(0..<3, id: \.self) { index in
Text(self.colorNames2[index]).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
Text("Color 2: \(color2)")
}
.padding()
}
}
}
这是在iOS 13.4 / Xcode 11.4下运行的
【问题讨论】:
-
是的,值得向 Apple 提交反馈。
-
我没有使用 SwiftUI(只是将小部件放在情节提要中),并且在更新片段中的文本时看到了同样的问题。我在我的段标题中显示项目计数,因此需要定期更新它们。我还没有找到解决办法。
标签: swiftui ios13 segmentedcontrol