I created the circle with deck of cards, that user can spin to select one. After the paning ends, it snaps to designated angle with a nice deceleration animation. In future there will some kind of indication that the card at 45 degrees is the selected one.
I would like to indication that the selection changed with haptic feedback, just like in UIPickerView
. For now I am trying to add haptic feedback to the deceleration animation. My idea was to make feedback generator and call .selectionChanged()
in animation as many times as number of cards that were skipped. But for now I decided to just simply call it 3 times. Unfortunately, none of my ideas work - even creating a separate UIViewPropertyAnimator
does not work. I suppose I should only put animatable properties in animation closure. The animator itself works right - the deceleration animation works.
animator.addAnimations {
UIView.animateKeyframes(withDuration: 5.0, delay: 0.0, options: [], animations: {
UIView.addKeyframe(withRelativeStartTime: 1.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
UIView.addKeyframe(withRelativeStartTime: 2.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
UIView.addKeyframe(withRelativeStartTime: 3.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
})
}
animator.startAnimation()
How can I mimic the haptic feedback behaviour of for example DatePicker , which vibrates when selection changes?