gpt4 book ai didi

iphone - 当 selectRow 动画完成时,如何从 UIPickerView 获取回调?

转载 作者:行者123 更新时间:2023-12-03 20:50:23 24 4
gpt4 key购买 nike

我有一个 UIPickerView,我希望在 selectRow 动画完成时收到通知。

我在 View Controller 中尝试了以下方法,该方法引用了 UIPickerView 但不起作用:

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

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

}

}

然后在我的代码中的某个位置启动动画:

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

最佳答案

您需要将方法调用嵌套到 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...
}

关于iphone - 当 selectRow 动画完成时,如何从 UIPickerView 获取回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/703293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com