gpt4 book ai didi

iphone - 基本关键帧动画(旋转)

转载 作者:行者123 更新时间:2023-12-03 18:24:39 25 4
gpt4 key购买 nike

我正在尝试创建一个非常简单的关键帧动画,其中图形通过给定的中点从一个角度旋转到另一个角度。

(目的是能够通过大于 180 度的 OBTUSE 弧角来制作旋转动画,而不是让动画“作弊”并走最短路线,即通过相反的路线 , ACUTE 较小的角度——当只有一个[即目的地]关键帧时可能会发生这种情况。为了走得更远,我假设我需要一个额外的关键帧,沿着所需的弧线。)

这是我到目前为止所得到的(它确实通过最锐角使图形达到所需的旋转):

#define DEGREES_TO_RADIANS(__ANGLE__) ((__ANGLE__) / 180.0 * M_PI)

...

[UIView beginAnimations:nil context:nil];
CGAffineTransform cgCTM = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(desiredEndingAngle));
[UIView setAnimationDuration:0.5];
graphic.transform = cgCTM;
[UIView commitAnimations];

据我了解,我并不是在寻找沿着路径的动画(因为那是为了平移,而不是旋转)......

无论如何,我们将非常感谢任何帮助!提前致谢。

最佳答案

我想我已经明白了。

以下代码(在本示例中)执行完整 270 度旋转(1.5*pi 弧度),包括可以进一步自定义的各种参数:

CALayer *layer = rotatingImage.layer;
CAKeyframeAnimation *animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
animation.duration = 0.5f;
animation.cumulative = YES;
animation.repeatCount = 1;
animation.values = [NSArray arrayWithObjects: // i.e., Rotation values for the 3 keyframes, in RADIANS
[NSNumber numberWithFloat:0.0 * M_PI],
[NSNumber numberWithFloat:0.75 * M_PI],
[NSNumber numberWithFloat:1.5 * M_PI], nil];
animation.keyTimes = [NSArray arrayWithObjects: // Relative timing values for the 3 keyframes
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:.5],
[NSNumber numberWithFloat:1.0], nil];
animation.timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn], // from keyframe 1 to keyframe 2
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]; // from keyframe 2 to keyframe 3
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;

[layer addAnimation:animation forKey:nil];

谢谢!

关于iphone - 基本关键帧动画(旋转),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1031177/

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