gpt4 book ai didi

ios - CAShapeLayer路径动画——缩小一个圆

转载 作者:行者123 更新时间:2023-11-29 03:11:22 25 4
gpt4 key购买 nike

我正在尝试缩小圆形 CAShapeLayer,但使用关键路径“路径”似乎不起作用。

CGPathRef startPath = [UIBezierPath bezierPathWithOvalInRect:startRect].CGPath;
CGPathRef endPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(startRect, 15, 15)].CGPath;

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 1.0;
animation.fromValue = (__bridge id)startPath;
animation.toValue = (__bridge id)endPath;
animation.autoreverses = YES;
animation.repeatCount = CGFLOAT_MAX;
animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.6 :0.3 :0.8 :0.45];

//circleLayer is a CAShapeLayer
[self.circleLayer addAnimation:animation forKey:@"pathAnimation"];

我认为我一定误解了路径动画的工作原理,因为如果我尝试对不透明度或变换进行动画处理,几乎相同的代码似乎可以正常工作。

有什么想法吗?

最佳答案

我最近遇到了同样的问题,最终通过创建圆来解决它,然后为比例 CGAffineTransform 设置动画。在图层为圆形的 View 中,我简单地使用了

CGAffineTransform transform = CGAffineTransformIdentity;
transform = CGAffineTransformScale(transform, scaleX, scaleY);

[UIView animateWithDuration: 0.5 animations: ^{
self.transform = transform;
}];

希望这对您有所帮助!

关于ios - CAShapeLayer路径动画——缩小一个圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22212481/

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