UIPickerView selectRow:inComponent:animated With smooth animation
i was trying to create a Slot machine(type off slot machine but you can say at UI level it will work like Slot machine) So I use UIPickerView
and some how i made it circular. But when i rotate it using function selectRow:inComponent:animated:
with animate开发者_如何学God value YES
. its animation is bit sloppy or you can say that not cool enough when we spin UIpickerview
from hands.
Sloppy animation means, when we move UIPickerView
with hands, it decreases its speed at the end of animation and this effect looks very good but when I use function selectRow:inComponent:animated:
I can't get that animation.
Is there a way to get that animation???
Did you try getting the recursive description the uipickerview? I think that some where there should be a scrollview inside. try getting the scrollview reference and make it scroll to the desired position with a custom animation. To get the view hierarchy try using recursive description on the picker view. It's just a hint. Hope that this helps.
Not sure if it is still relevant but as I stumbled on the same issue I made an extension for the UIPickerView with fakes the slow animation.
extension UIPickerView {
func slowSelectRow(_ row: Int, inComponent component: Int = 0) {
let currentSelectedRow = selectedRow(inComponent: component)
guard currentSelectedRow != row else {
return
}
let diff = (currentSelectedRow > row) ? -1 : 1
let newRow = currentSelectedRow + diff
selectRow(newRow, inComponent: component, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
self.slowSelectRow(row, inComponent: component)
}
}
}
精彩评论