设置 CGAffineTransform 的起点
我使用遵循 CGPathAddEllipseInRect 的 CAKeyframeAnimation 沿着圆圈对 UIView 进行动画处理。但是,无论视图最初位于哪个框架,视图似乎总是从同一个位置开始。是否有某种方法可以调整视图在路径上的起始位置?
谢谢!
CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
myAnimation.fillMode = kCAFillModeForwards;
myAnimation.repeatCount = 5;
myAnimation.calculationMode = kCAAnimationPaced;
myAnimation.duration = 10.0;
CGMutablePathRef animationPath = CGPathCreateMutable();
CGPathAddEllipseInRect(animationPath, NULL, rect);
myAnimation.path = animationPath;
CGPathRelease(animationPath);
[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"];
I am animating a UIView along a circle using a CAKeyframeAnimation that follows a CGPathAddEllipseInRect. However, the view always seems to start in the same place regardless of the frame it is originally positioned in. Is there some way to adjust the starting position of the view on the path?
Thanks!
CAKeyframeAnimation *myAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
myAnimation.fillMode = kCAFillModeForwards;
myAnimation.repeatCount = 5;
myAnimation.calculationMode = kCAAnimationPaced;
myAnimation.duration = 10.0;
CGMutablePathRef animationPath = CGPathCreateMutable();
CGPathAddEllipseInRect(animationPath, NULL, rect);
myAnimation.path = animationPath;
CGPathRelease(animationPath);
[view.layer addAnimation:myAnimation forKey:@"changeViewLocation"];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为不可能为 CGPathAddEllipseInRect 设置起点。 (至少我没有成功)
而不是使用:CGPathAddEllipseInRect,
您应该使用:CGPathAddArc! 例如:
将从底部开始顺时针旋转整圈。更改 startVal 值可更改旋转起始位置。 (完整旋转为 2*M_PI)。
I don't think it's possible to set a start point for CGPathAddEllipseInRect. (At least i wasn't successful)
instead of using: CGPathAddEllipseInRect,
You should use: CGPathAddArc! For example:
will rotate full circle starting from bottom - clockwise. Change startVal value to change rotation start position. (full rotation is 2*M_PI).
以前的答案是正确的并且有效,但应该有
而不是
否则,M_PI 将四舍五入为整数,并且您将无法获得准确的角度。
PS 声誉较低,无法评论之前的答案,抱歉。
Previous answer is correct and works, but there should be
instead of
Otherwise, M_PI will be rounded to integer and you won't be able to achieve accurate angle.
P.S. has low reputation to comment the previous answer, sorry.