filipealva / PickerView

🔸 A customizable alternative to UIPickerView in Swift.
MIT License
527 stars 92 forks source link

[FEATURE] Animated item selection #21

Open D-Link13 opened 7 years ago

D-Link13 commented 7 years ago

I would like to animate highlighting in styleForLabel, so i've overrides this method like this: if highlighted { UIView.animate(withDuration: 0.5, animations: { label.transform = CGAffineTransform(scaleX: 1, y: 1) }) } else { UIView.animate(withDuration: 0.5, animations: { label.transform = CGAffineTransform(scaleX: 1/2.5, y: 1/2.5) }) } But this gives me negative effect - it tries to animate labels before the view appears... So i decided to give my VC an extra property - var beginAnimating = false, and set this to true in viewDidApear. Unfortunately this is not working as I expect =( Please give me some advices with this issue. Thanks!

filipealva commented 7 years ago

The highlight occurs during a reload of PickerView. Since PickerView is built upon UITableView it happens during a reloadData, maybe you would need to wrap this animation in this code:

tableView.beginUpdates()
// animation code
tableView.endUpdates()

I think it could work.