HI
在UipickerView的iPhone应用程序中,我可以以编程方式向上或向下移动选择器值
添加像picker这样的动画效果只会移动自己 那个
[picker selectRow:0 inComponent:0 animated:YES];
---- ---
//here I need Some time delay
[picker selectRow:3 inComponent:0 animated:YES];
如何在执行这两个陈述之间给出一些时间延迟
请帮助和建议
谢谢
答案 0 :(得分:2)
如果您想添加一些延迟,可以使用:
[NSThread sleepForTimeInterval:0.5];
但这会阻止您的应用程序,因此最好使用计时器:
//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];
}
这应该在主线程上执行,因为UIKit不是线程安全的
答案 1 :(得分:0)
你的意思是这个方法
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
答案 2 :(得分:0)
您可以尝试在延迟performSelector: withObject: afterDelay:
方法
答案 3 :(得分: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];
它对我来说就像一个魅力!
我认为这将无法奏效,但它非常好!