SwiftUI: How to get continuous updates from Slider

后端 未结 6 1752
悲哀的现实
悲哀的现实 2020-12-11 01:56

I\'m experimenting with SwiftUI and the Slider control like this:

struct MyView: View {

    @State private var value = 0.5

    var body: some View {
               


        
6条回答
  •  一生所求
    2020-12-11 02:30

    I am not able to reproduce this issue on iOS 13 Beta 2. Which operating system are you targeting?

    Using a custom binding, the value is printed for every small change, not only after editing ended.

    Slider(value: Binding(getValue: {0}, setValue: {print($0)}))
    

    Note, that the closure ({ pressed in }) only reports when editing end starts and ends, the value stream is only passed into the binding.

提交回复
热议问题