iPhone设置了一些时间延迟

发布于 2024-10-20 21:07:40 字数 335 浏览 5 评论 0原文

你好;

在我的 iPhone 应用程序中的 UipickerView 中,我可以通过编程方式向上或向下移动选取器值吗?

添加像选取器仅移动自身这样的动画效果 为此,


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

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

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

我怎样才能在这两个语句的执行之间给出一些时间延迟

请帮助并建议

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

长亭外,古道边 2024-10-27 21:07:40

如果你想添加一些延迟,你可以使用:

[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 不是线程安全的

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

知足的幸福 2024-10-27 21:07:40

你说的是这个方法

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

You mean this method

- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated
御守 2024-10-27 21:07:40

您可以尝试通过 performSelector: withObject: afterDelay: 方法在延迟后调用第二个选择

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

站稳脚跟 2024-10-27 21:07:40

这个怎么样:

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

它对我来说就像魅力一样!

我以为这永远不会成功,但它非常好!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文