IOS,如何仅在CABasicAnimation上删除一次图层

时间:2014-05-21 06:42:09

标签: ios cabasicanimation

我已将this code修改为代码,如下所示。我正在使用触摸事件触发下面的功能来运行动画。我试图实现的结果是:每次触摸1次,图像层只删除1次。我面临的问题是当我将removedOnCompletion设置为YES时,无论该层感觉它已经移除了一次但是它从未被移除,因此程序被卡在同一层上。如果我将removedOnCompletion保留为NO,则图片图层会自动删除所有图层。

那么,我怎样才能确保每次进程只删除1个图像层?任何帮助表示赞赏。

-(void)animate:(id)sender {
//Dont implicitly animate the delay change
[CATransaction setDisableActions:YES];

//Reset the replicator delays to their origonal values
imageLayer.instanceDelay = X_TIME_DELAY;
//Re-enable the implicit animations
[CATransaction setDisableActions:NO];

//Create the transform matrix for the animation

//Move forward 1000 units along z-axis
CATransform3D t = CATransform3DMakeTranslation( -500, -500, 1000);

//Rotate Pi radians about the axis (0.7, 0.3, 0.0)
t = CATransform3DRotate(t, M_PI, 0.7, 0.3, 0.0);
//Scale the X and Y dimmensions by a factor of 3
t = CATransform3DScale(t, 0.5, 0.5, 1);

//Transform Animation
CABasicAnimation *animation = [CABasicAnimation animation];
animation.fromValue = [NSValue valueWithCATransform3D: CATransform3DIdentity];
animation.toValue = [NSValue valueWithCATransform3D: t];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"transform"];

//Opacity Animation
animation = [CABasicAnimation animation];
animation.fromValue = [NSNumber numberWithFloat:1.0];
animation.toValue = [NSNumber numberWithFloat:0.0];
animation.duration = 1.0;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
[subLayer addAnimation:animation forKey:@"opacity"];
stuckfile = NO;
}

0 个答案:

没有答案