CAShapeLayer子视图没有正确动画

时间:2013-11-10 19:46:08

标签: ios objective-c core-animation calayer cashapelayer

我正在尝试将CALayer用于动画。我想要的是收缩和反弹(有效)的圆圈以及用于展开和淡出like this的描边圆圈。不幸的是,subLayer上的第二个环没有动画。我不知道为什么。

我像我这样设置我的图层

- (void)setLayerProperties {
    //The view’s Core Animation layer used for rendering.
    CAShapeLayer *layer = (CAShapeLayer *)self.layer;

    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)
                                                      byRoundingCorners:UIRectCornerAllCorners
                                                            cornerRadii:self.frame.size];
    layer.path = bezierPath.CGPath;
    layer.fillColor = _Color.CGColor;

    rippleLayer = [[CAShapeLayer alloc] init]; // update from Andrea's answer
    layer.path = bezierPath.CGPath;
    layer.strokeColor = [UIColor blueColor].CGColor;
    [layer addSublayer:rippleLayer];
}

然后我使用这些函数设置动画

- (void)pop{
    CABasicAnimation *animation = [self animationWithKeyPath:@"transform.scale"];
    [animation setFromValue:[NSNumber numberWithFloat:1.0f]];
    [animation setToValue:[NSNumber numberWithFloat:0.8f]];
    [animation setRemovedOnCompletion:YES];
    [animation setDuration:0.15];
    [animation setAutoreverses:YES];

    [self.layer addAnimation:animation forKey:animation.keyPath];

    rippleLayer.anchorPoint = CGPointMake(1, 1);
    CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    [scale setFromValue:[NSNumber numberWithFloat:1.0f]];
    [scale setToValue:[NSNumber numberWithFloat:2.0f]];
    [scale setRepeatCount:1];
    [scale setDuration:1.0f];
    //r[scale setRemovedOnCompletion:YES];
    [scale setFillMode:kCAFillModeForwards];

    [rippleLayer addAnimation:scale forKey:scale.keyPath];
}

1 个答案:

答案 0 :(得分:2)

您似乎正在将rippleLayer创建为普通的CALayer,而不是CAShapeLayer。就我记忆而言,path不是CALayer的属性,并且您将获得与之前相同的层的路径。所以你要添加一个完全没有内容的简单图层。