0

順番に再生するボールブラストエフェクトを実行しようとしています。続々。

私がまだやったこと:

ボールブラスト効果のために私が使用した

UIButton *ballButton = (UIButton *)[cell viewWithTag:10];

ballButton.imageView.animationImages = [[NSArray alloc] initWithObjects:
                                        [UIImage imageNamed:@"1.png"],
                                        [UIImage imageNamed:@"2.png"],
                                        [UIImage imageNamed:@"3.png"],
                                        [UIImage imageNamed:@"4.png"],
                                        nil];
ballButton.imageView.animationDuration = 1;
ballButton.imageView.animationRepeatCount = 1;

このコード行は、コレクション ビューのセル内の複数のボタンに関連付けられています。ballbutton.imageview私はこれらをこのようなアニメーションの開始と呼びます

[UIView animateWithDuration:1 delay:5 options:UIViewAnimationOptionCurveEaseOut animations:^{
        NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0];
        UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2];
        UIButton *ballObject = (UIButton *) [cell viewWithTag:10];
        [ballObject.imageView startAnimating];
    } completion:^(BOOL b){
          NSLog(@" here i call next animation of ball blast to execute ");
}];

このように3つのアニメーションボタンを入れ子にしました。

4

2 に答える 2

0

このようにして私は私の問題を解決しました。最初はこれを呼び出してアニメーションを開始しました

        [self startAnim:index];

この StartAnim をこのように実装し、問題を解決しました。

-(void)StartAnim :(int)x{

    NSIndexPath *path2 = [NSIndexPath indexPathForRow:x inSection:0];
    UICollectionViewCell *cell = [ballContainer cellForItemAtIndexPath:path2];
    UIButton *ballObject = (UIButton *) [cell viewWithTag:10];
    [ballObject setBackgroundImage:nil forState:UIControlStateNormal];
    ballObject.imageView.image = nil;
    [ballObject.imageView startAnimating];

    double delayInSeconds = 0.15;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

        if(x-6>=0){
            [self StartAnim :(x-6)];
        }
    });



}
于 2013-07-11T04:22:03.547 に答える
0

まず、他の 3 つすべてに対して 1 つの大きなアニメーションを作成してみませんか? つまり、フレームを ( 200,200 UIView animateWithDuration:) から (0,0) に設定すると、1 秒の時間に比例して移動します。しかしUIImageView、アニメーションに関する のプロパティは、アニメーションが既に作成されているように作成されています。

個人的には、次のようにタイマーを使用することをお勧めします。

NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:ballObject.imageView.animationDuration
                                                  target:self 
                                                selector:@selector(performNextAnimation:) 
                                                userInfo:nil repeats:NO];
[ballObject.imageView startAnimating];

そしてperformNextAnimationメソッドで:

- (void) performNextAnimation{
[timer invalidate]; // you have to access the timer you've scheduled with the animation
timer = nil;
/* code for starting the next animation */
}
于 2013-07-07T09:41:50.190 に答える