gpt4 book ai didi

animation - 核心动画 : why can I not composite two animations?

转载 作者:行者123 更新时间:2023-11-29 11:24:17 25 4
gpt4 key购买 nike

我正在尝试为轮子制作动画

当手指停留 > 0.1 秒时,轮子“弹出”,即我将 Scale 从 1.0 设置为 1.2。

当手指移动时,轮子会随之转动(只有弹出时才有效)。

但我遇到了一个问题:它一开始旋转,比例就缩小回 1.0。

- (void) spin: (Direction) direction
{
float thetaOld = thetaWheel;

float k = (direction == AntiClockwise) ? -1 : 1;
float t = 2 * M_PI * ( k / 12.0 );
thetaWheel += t;

CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath:@"transform"];

anim.fromValue = [NSNumber numberWithDouble: thetaOld];
anim.toValue = [NSNumber numberWithDouble: thetaWheel];

anim.valueFunction = [CAValueFunction functionWithName: kCAValueFunctionRotateZ];

anim.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

anim.duration = 0.1f;
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;

[self.wheelLayer addAnimation: anim forKey:@"transform"];
}

- (void) popOut
{
CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

anim.fromValue = [NSNumber numberWithDouble: 1.0];
anim.toValue = [NSNumber numberWithDouble: 1.2];

anim.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

anim.duration = 0.25f;
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;

[self.wheelLayer addAnimation: anim forKey:@"transform.scale"];
}

// doesnt get used yet
- (void) popBack
{
CABasicAnimation * anim = [CABasicAnimation animationWithKeyPath:@"transform.scale"];

anim.fromValue = [NSNumber numberWithDouble: 1.2];
anim.toValue = [NSNumber numberWithDouble: 1.0];

anim.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];

anim.duration = 0.1f;
anim.fillMode = kCAFillModeForwards;
anim.removedOnCompletion = NO;

[self.wheelLayer addAnimation: anim forKey:@"transform.scale"];
}

最后一个例程暂时用不到!所以我看不出是什么将比例缩小回 1...

看起来第二个动画以某种方式覆盖了第一个...

如何正确地做到这一点?

最佳答案

我猜想(尚未测试)在“变换”keyPath 的动画中应用的图层变换会覆盖您在缩放动画中应用的变换。

对于旋转,请尝试使用带有 transform.rotation.z 键路径的动画(在这种情况下您不需要设置 valueFunction)

关于animation - 核心动画 : why can I not composite two animations?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4272296/

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