selectRow动画完成后,如何从UIPickerView获取回调? [英] How to get callback from UIPickerView when the selectRow animation is done?

查看:62
本文介绍了selectRow动画完成后,如何从UIPickerView获取回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIPickerView,并且当selectRow动画完成后我想得到通知.

I have a UIPickerView and I would like to be notified when the selectRow animation is done.

我在视图控制器中尝试了以下方法,该方法具有对UIPickerView的引用,但无法正常工作:

I tried the following approach in my view controller which has a reference to the UIPickerView and it won't work:

-(void)viewDidLoad
{
    ...
    [UIPickerView setAnimationDelegate:self];
    [UIPickerView setAnimationDidStopSelector:@selector(animationFin ished:finished:context];
    ...
}

- (void)animationFinishedNSString *)animationID finishedBOOL)finished contextvoid *)context
{
    if (finished) {

    }

}

然后在代码中的某个地方启动动画:

Then somewhere in my code, I initiate the animation:

[picker selectRow:random() % pickerDataCount inComponent:0 animated:YES];

推荐答案

您需要将方法调用嵌套在beginAnimations/commitAnimation块中.

you need to nest the method call into a beginAnimations/commitAnimation block.

- (void) animationFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
    NSLog(@"Here I am");
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

    [UIView beginAnimations:@"1" context:nil]; // nil = dummy
    [UIPickerView setAnimationDelegate:self];
    [UIPickerView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
    [myPickerView selectRow:0 inComponent:0 animated:YES]; // jump with any swipe in picker always to row=0 as dummy to initiate animation
    [UIView commitAnimations];

    //...whatever comes in addition...
}

这篇关于selectRow动画完成后,如何从UIPickerView获取回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆