user1561346
user1561346

Reputation: 502

Stop UIPickerViewAnimation

Is there a way to instantly stop the animation of rolling UIPIckerView or UIDatePicker on button click.

Upvotes: 1

Views: 361

Answers (2)

Byte
Byte

Reputation: 2940

Look into - (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component

Since Picker can only show limited number of results at a time. You can implement an algorithm to determine what is in the middle of the result when this method is called. It gets called every time a new option appears (just like tableView viewForIndexPath). So scrolling up or down will call this method.

Beware, you would need to add padding options to first few choices and last few choices just so that it works correctly. This will get you the effect you want. Be warned, Apple might not agree with this method as it doesnt act like what Apple intended picker to do.

Let me know if it works.

Upvotes: 1

ravron
ravron

Reputation: 11211

If you look at the UIPickerView class reference, you'll see:

selectRow:inComponent:animated:

Selects a row in a specified component of the picker view.

- (void)selectRow:(NSInteger)row 
      inComponent:(NSInteger)component 
         animated:(BOOL)animated

You could call this method when your button is pushed, sending NO for the animated parameter, to instantly select a particular row.

Upvotes: 0

Related Questions