gpt4 book ai didi

ios - QuartzCore 动画形状?

转载 作者:行者123 更新时间:2023-11-28 18:36:52 28 4
gpt4 key购买 nike

我环顾四周,找不到办法,基本上我想做形状动画,如下图所示。这实际上可以用 iOS 6 API 甚至 iOS 7 API 来完成吗? CAAnimation 中的所有内容似乎都是将整个层移动到另一个 CGPoint 而不是形状的一部分。

enter image description here

我猜我可以手动完成,将 NSTimer 设置为 1/24 或 1/60,计算我的形状变化并重新绘制增量偏移,直到达到所需的形状,但显然我想利用 Apple 的易用性-如果 Apple 有这方面的 API,那么也可以缓和计时效果(并节省大量开发时间)。 TY.

最佳答案

您可以使用 CAShapeLayer,它有一个属性 path,它是可动画的。您必须使用 Quartz 中的 CGPath 函数或使用 UIBezierPath 将形状创建为 CGPath

你必须这样做:

CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.bounds = CGRectMake(0.f, 0.f, 50.f, 50.f);
shapeLayer.position = CGPointMake(50.f, 50.f);
shapeLayer.fillColor = [[UIColor redColor] CGColor];
shapeLayer.path = [[UIBezierPath bezierPathWithOvalInRect:shapeLayer.bounds] CGPath];

[self.view.layer addSublayer:shapeLayer];

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.fromValue = (__bridge id) [[UIBezierPath bezierPathWithOvalInRect:shapeLayer.bounds] CGPath];
animation.toValue = (__bridge id) [[UIBezierPath bezierPathWithRect:shapeLayer.bounds] CGPath];
animation.repeatCount = NSIntegerMax;
animation.duration = 2.0;
animation.autoreverses = YES;

[shapeLayer addAnimation:animation forKey:@"shapeAnimation"];

如果 Core Animation 的插值没有按预期工作,您应该查看 CAKeyframeAnimation

关于ios - QuartzCore 动画形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280393/

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