2

UIPickerView があり、selectRow アニメーションが完了したときに通知を受け取りたいです。

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

3 に答える 3

2

メソッド呼び出しを beginAnimations/commitAnimation ブロックにネストする必要があります。

- (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...
}
于 2009-04-17T09:50:53.333 に答える
1

関心のあるコンポーネントと行のビューを要求するときに、viewForRow から自分自身に通知を投稿できます。

行とコンポーネントをプロパティとして保持し、selectRow を呼び出す前に設定するだけです。そして、viewForRow で

if ( (component == [self component] && (row == [self row] ) 通知を自分に投稿する

于 2009-09-23T23:02:35.573 に答える