CAShapeLayer路径动画-缩小圆圈 [英] CAShapeLayer path animation -- shrinking a circle

查看:169
本文介绍了CAShapeLayer路径动画-缩小圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试缩小圆形CAShapeLayer,但使用关键路径'path'似乎无效。

I'm trying to shrink a circular CAShapeLayer but using the key path 'path' does not seem to be working.

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"];

我想我对路径动画的工作方式会产生误解,因为几乎相同的代码似乎可以正常工作如果我尝试设置不透明度或变换的动画。

I think i must be misunderstanding about how a path animation works because pretty much identical code seems to work fine if i am try to animate, say, the opacity or the transform.

有什么想法吗?

推荐答案

我最近遇到了同样的问题,最终通过创建圆解决了问题,然后为CGAffineTransform缩放了动画。在以圆为图层的视图中,我只是使用了

I recently had the same question and ended up solving it by creating the circle, then animating the scale CGAffineTransform. In the view whose layer is the circle, I simply used

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

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

希望这会有所帮助!

这篇关于CAShapeLayer路径动画-缩小圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆