gpt4 book ai didi

ios - RotationMode 在 CAKeyframeAnimation(线性路径)中不起作用

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

只要 View 通过路径(线性路径),我就会尝试让 View 旋转,但它不会旋转。

这是我的代码:

 CAKeyframeAnimation *animKF = [CAKeyframeAnimation animationWithKeyPath:@"position"];
animKF.values = [NSArray arrayWithObjects:[NSValue valueWithCGPoint:CGPointMake(100, 100)], [NSValue valueWithCGPoint:CGPointMake(400, 400)], [NSValue valueWithCGPoint:CGPointMake(700, 100)], [NSValue valueWithCGPoint:CGPointMake(1000, 400)], nil];

animKF.keyTimes = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.25], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:1.0], nil];

animKF.duration = 6;

animKF.rotationMode = kCAAnimationRotateAuto;

[imageView.layer addAnimation:animKF forKey:@"keyframe"];

但是imageView(图中蓝色的脸)并没有沿着path(图中红色的线)旋转

Path

非常感谢。

最佳答案

来自 rotationMode 的文档:

The effect of setting this property to a non-nil value when no path object is supplied is undefined.

在您的代码中,您正在设置关键帧动画的 values 属性,但您需要设置一个 path相反。


您应该根据您的值创建一个 CGPath 并将其设置为您的关键帧的路径。

UIBezierPath *animationPath = [UIBezierPath bezierPath];
[animationPath moveToPoint:CGPointMake(100, 100)];
[animationPath addLineToPoint:CGPointMake(400, 400)];
[animationPath addLineToPoint:CGPointMake(700, 100)];
[animationPath addLineToPoint:CGPointMake(1000, 400)];

animKF.path = animationPath.CGPath;

关于ios - RotationMode 在 CAKeyframeAnimation(线性路径)中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13699303/

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