【发布时间】:2020-06-25 19:59:43
【问题描述】:
如何在滑块上循环我的 Dic 键?滑块行为是将第一个键除以最后一个键。我想要的只是循环通过键值然后以某种方式返回值的值......
struct ContentView: View {
@State private var currentValue = 0.0
@ObservedObject var scoreModel = ScoreModel()
var body: some View {
let endValue = Dictionary(uniqueKeysWithValues:
scoreModel.eventMDL.map { key, value in (key, value) })
return VStack {
Slider(value: $currentValue, in: endValue.keys.sorted()[1]...endValue.keys.sorted()[27])
.rotationEffect(Angle(degrees: -90))
Spacer()
Text("\(currentValue, specifier: "%.0f")")
}
.frame(height: 280)
}
}
型号:
@Published var eventMDL = [340.0: 100.0,
330.0: 97.0,
320.0: 94.0,
310.0: 92.0,
300.0: 90.0,
290.0: 88.0,
280.0: 86.0,
270.0: 84.0,
260.0: 82.0,
250.0: 80.0,
240.0: 78.0,
230.0: 76.0,
220.0: 74.0,
210.0: 72.0,
200.0: 70.0,
190.0: 68.0,
180.0: 65.0,
170.0: 64.0,
160.0: 63.0,
150.0: 62.0,
140.0: 60.0,
130.0: 50.0,
120.0: 40.0,
110.0: 30.0,
100.0: 20.0,
90.0: 10.0,
80.0: 0.0,
0.0 : 0.0]
【问题讨论】:
标签: dictionary slider swiftui