IPhone set some time delay

HI;

In my iPhone app in UipickerView, I can move the selection icons up or down Programmatically

To add an animation effect, such as a picker, moves just 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 the execution of these two statements

Please help and suggest

thank

+3
source share
4 answers

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

[NSThread sleepForTimeInterval:0.5];

But this will block your application, so it is 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 done in the main thread, since UIKit is not thread safe

+2
source

Do you mean this method

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

performSelector: withObject: afterDelay:

0

:

[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];

!

, , !

0
source

Source: https://habr.com/ru/post/1796743/


All Articles