【发布时间】:2012-11-26 13:01:42
【问题描述】:
我有一个 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");
}
}
【问题讨论】:
-
如果您在使用旧密钥添加新动画调用
removeAnimationForKey:时会发生什么情况。你还收到finished = YES吗? -
是的,删除动画会导致设置布尔值,finished = NO。这确实有将我的图层重置回其原始位置的副作用,但我认为这一定是要走的路。当我找到解决方案时会回复。谢谢。
标签: ios core-animation cabasicanimation