我有一个 UIView 和两个 UISwipeGesture 类,它们在 0 和 -99 之间为 X 旋转设置动画,从而提供翻转板效果。如果用户向下滑动然后立即向上滑动,则“向下滑动”动画过早结束并开始向上滑动动画。
我如何判断它是否由于添加了另一个动画而提前结束?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");
}
}