开发者

How do I make a picker appear to spin around multiple times?

I am trying to make a picker appear to spin around multiple times before landing on a particular row. I have tried using for and do while loops. I have even tried calling multiple methods in succession, but each time, the picker only appears to reload once even though I am telling it to reload multiple times before finally landing on a selected row like this:

int newValue = random() % [self.inputNames count];
[payPicker selectRow:newValue inComponent:0 animated:YES];
[payPicker reloadComponent:0];
NSDate *future = [NSDate dateWithTimeIntervalSinceNow: 2.0 ];
[NSThread sl开发者_如何学编程eepUntilDate:future];

newValue = random() % [self.inputNames count];
[payPicker selectRow:newValue inComponent:0 animated:YES];
[payPicker reloadComponent:0];

[NSThread sleepUntilDate:future];

I do the above about three or four times and each time the picker only appears to reload once and goes to the final selected row. Is there something special I have to do or is it possible at all to make the picker appear to spin around and around? If I could even get it to jump randomly between the row choices before landing on one, I would be fine with that. Thanks!!


Don't sleep the UI thread. No animation will start until you exit this method, after all your sleeping. So return from the method with the first request for the picker to animate. Do subsequent picker animation requests in timer callbacks after the previous picker animation has finished. Rinse and repeat as necessary.

The way other apps do this is by not using a real picker at all, but overlaying the picker control with an animated image sequence which just happens to look like a picker spinning. Then remove the fake animation to show an identical looking but real picker underneath. The advantage of your own animated cartoon is that you can make the fake picker spin in ways that a real picker can't.


Perhaps you could try selecting random rows before selecting your actual row. For example, if you want to select row 0, select rows in the following order - 9, 2, 15, 0. I don't think picker view will rotate if it is already on the row it is supposed to go to.

Also, you should select the rows every time after your pickerView:didSelectRow:inComponent: method hits.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜