I am new to SwiftUI programming, and I currently am working on a mock-up project where I want to create an iPhone timepicker simulator.
Part of the codes are shown below and the main part is inspired by the tutorial given by The Swift Academy (https://www.youtube.com/watch?v=AmEEjsXhKIg). What I am trying to do here is to have the iPhone repeatedly provide haptic feedback as long as the timepicker wheel is rolling. Ideally the haptic feedback is given at the same time when numbers are refreshed, but it only happens once when the wheel scrolling stops. Is there any solution to fix this? Any idea will be much appreciated :)
Here are some codes that I already wrote down.
import SwiftUI
import CoreHaptics
struct ContentView: View {
@State var hourSelection = 0
var hours = [Int](0..<24)
var body: some View {
Picker(selection: self.$hourSelection, label: Text("")) {
ForEach(0..<self.hours.count) {index in
Text("\(self.hours[index])h").tag(index)
prepareHaptics()
HapticEvent()
}
}.pickerStyle(WheelPickerStyle())
}
//make haptic engine ready
func prepareHaptics(){...}
//play haptic pattern
func HapticEvent(){...}
}