【发布时间】:2015-10-14 09:35:50
【问题描述】:
您好,我正在使用 CABasicAnimation 为 CAShapeLayer 中的路径设置动画。当用户点击我调用的按钮时:
CABasicAnimation *expandAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
expandAnimation.toValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,30,30)].CGPath;
expandAnimation.duration = 1.0;
expandAnimation.fillMode = kCAFillModeBoth;
expandAnimation.removedOnCompletion = NO;
[self.circleShape addAnimation:expandAnimation forKey:expandAnimation.keyPath];
当释放按钮时,我会像这样对其进行动画处理:
CABasicAnimation *narrowAnimation = [CABasicAnimation animationWithKeyPath:@"path"];
narrowAnimation.fromValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,0,30,30)].CGPath;
narrowAnimation.toValue = (id)[UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 5, 20, 20)].CGPath;
narrowAnimation.duration = .5;
narrowAnimation.fillMode = kCAFillModeBoth;
narrowAnimation.removedOnCompletion = NO;
[self.circleShape addAnimation:narrowAnimation forKey:narrowAnimation.keyPath];
有时当我开始第二个动画时,第一个动画仍在动画。我到底如何才能获得第一个动画的当前状态,以便我可以将第二个动画的起始值设置为从该状态开始?
对于我使用 BezierPaths 的值。
【问题讨论】:
-
在做下一个动画之前你有没有尝试
[layer removeAnimationForKey:@"path"];? -
这不是我认为的问题。当我调用第二个动画时,第一个动画会自动停止。我只想让圆圈从当前状态开始缩小,而不是从最大尺寸开始。
-
谢谢,我现在明白这个问题了。
标签: ios objective-c animation cashapelayer cabasicanimation