1

UIView と 2 つの UISwipeGesture クラスがあり、X 回転を 0 から -99 の間でアニメートし、フリップ ボード効果を与えます。ユーザーが下にスワイプしてからすぐに上にスワイプすると、「下にスワイプ」のアニメーションが途中で終了し、上にスワイプのアニメーションが開始されます。

別のアニメーションが追加されたために途中で終了したかどうかはどうすればわかりますか? animationDidStop:finished メッセージが送信されますが、終了値は常に TRUE です。

下にスワイプするコードは次のとおりです。

CATransform3D transform = CATransform3DIdentity;

// This must be set before we calculate the transforms to give the 3D perspective (1.0 / -DISTANCE_FROM_CAMERA)
transform.m34 = 1.0 / -4000;
// Rotate on the X axis
transform = CATransform3DRotate(transform, DegreesToRadians(-99), 1, 0, 0);

// Apply transform in an animation
CABasicAnimation* foldDownAnimatnion = [CABasicAnimation animationWithKeyPath:@"transform"];
foldDownAnimatnion.duration = 1;
foldDownAnimatnion.toValue = [NSValue valueWithCATransform3D:transform];
foldDownAnimatnion.removedOnCompletion = NO;
foldDownAnimatnion.fillMode = kCAFillModeForwards;
foldDownAnimatnion.delegate = self;

// Identify this animation in delegate method
[foldDownAnimatnion setValue:@"foldDown" forKey:@"name"];
[foldDownAnimatnion setValue:theLayer forKey:@"layer"];


[theLayer addAnimation:foldDownAnimatnion forKey:nil];

そして私のデリゲートメソッド:

- (void)animationDidStop:(CAAnimation *)animation finished:(BOOL)finished
{
    if([[animation valueForKey:@"name"] isEqualToString:@"foldDown"])
    {
        // Why is this always YES??
        NSLog(@"Animation finished: %@", (finished)?@"Yes" : @"No");

    }
    else if([[animation valueForKey:@"name"] isEqualToString:@"foldUp"])
    {
        NSLog(@"animationDidStop: foldUp");

    }

}
4

2 に答える 2

0

2 つの BOOL インスタンス変数を追加します(BOOL UpAnimationStarted; BOOL DownAnimationStarted;) SwipeUp の開始時に UpAnimationStarted を YES に設定します。SwipeDown の開始時に、DownAnimationStarted を YES に設定します。これらの BOOL 値を使用して、アニメーションの中断を確認できます。

于 2012-11-26T13:59:47.060 に答える