SwiftUI: How to get continuous updates from Slider

后端 未结 6 1766
悲哀的现实
悲哀的现实 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:33

    Just use the onEditingChanged parameter of Slider. The argument is true while the user is moving the slider or still in contact with it. I do my updates when the argument changes from true to false.

    struct MyView: View {
    
        @State private var value = 0.5
    
        func update(changing: Bool) -> Void {
            // Do whatever
        }
    
        var body: some View {
            Slider(value: $value, onEditingChanged: {changing in self.update(changing) }) 
            { pressed in }
        }
    }
    

提交回复
热议问题