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
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
You mean this method
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
You can try calling the second selection after a delay through performSelector: withObject: afterDelay:
method
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!
精彩评论