gpt4 book ai didi

ios - CAShapeLayer subview 未正确设置动画

转载 作者:行者123 更新时间:2023-11-29 10:52:30 24 4
gpt4 key购买 nike

我正在尝试使用 CALayer 制作动画。我想要的是缩小和反弹的圆圈(有效)和一个扩大和淡出的描边圆圈 like this .不幸的是,子层上的第二个环没有动画。我不确定为什么。

我这样设置图层

- (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];
}

最佳答案

您似乎将 rippleLayer 创建为普通 CALayer,而不是 CAShapeLayer。据我所知,path 不是 CALayer 的属性,并且您正在为与以前相同的图层提供路径。因此,您要添加一个根本没有任何内容的简单层。

关于ios - CAShapeLayer subview 未正确设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19894269/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com