ios
ios

Reputation: 6164

iPhone set some time delay

HI;

In my iPhone App in UipickerView can I move picker Values up or down Programmatically

To add effect of an animation like picker is moving itself only for that


[picker selectRow:0 inComponent:0 animated:YES]; 

----    ---
//here I need Some time delay

[picker selectRow:3 inComponent:0 animated:YES]; 

How can I give some time delay between execution of this two statements

Please help and Suggest

Thanks

Upvotes: 3

Views: 5214

Answers (4)

Adam
Adam

Reputation: 158

what about this:

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.1];
[UIView setAnimationDelay:0.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

[self.pickerView selectRow:row inComponent:0 animated:NO];

[UIView commitAnimations];

It worked for me like a charm!

I thought this will never gonna work, but it is pretty fine!

Upvotes: 0

Julien
Julien

Reputation: 9432

If you want to add some delay, you could use :

[NSThread sleepForTimeInterval:0.5];

But this will block your application, so it can be better to use a timer :

//In your method :
[picker selectRow:0 inComponent:0 animated:YES]; 

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(animatePickerTimer:) userInfo:picker repeats:NO];


//In the same class


-(void)animatePickerTimer:(NSTimer *)timer;
{
    [self performSelectorOnMainThread:@selector(animatePicker:) withObject:(UIPickerView *)timer.userInfo waitUntilDone:NO];

    //Not sure if this is required, since the timer does not repeat
    [timer invalidate];
}

-(void)animatePicker:(UIPickerView *)picker
{
[picker selectRow:3 inComponent:0 animated:YES];
}

This should be performed on main thread, since UIKit is not thread safe

Upvotes: 2

visakh7
visakh7

Reputation: 26390

You can try calling the second selection after a delay through performSelector: withObject: afterDelay: method

Upvotes: 0

Robin
Robin

Reputation: 10011

You mean this method

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

Upvotes: 0

Related Questions