gpt4 book ai didi

ios - 动画 CALayer anchorPoint

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

我已成功为图层的位置和变换(旋转)制作动画。

现在,我需要为 anchor 设置动画,但所有尝试都失败了!即使我这样做:

2012... App[6437:403] layer: 1, KeyPath: anchorPoint, fromValue: NSPoint: {1.05, 0.5}, toValue: NSPoint: {1.05, 0.5}, Duration: 2.5

这是在为图层设置动画之前卡住的 NSLog。我得到的结果是图层在 X 轴上向左移动太远,然后返回......并重复(因为自动反转已打开)。

关于图层层次结构的注意事项:SuperLayer 有三个我正在应用动画的子层。

为什么? anchor 应该如何动画?

我的代码:

    NSArray* subKeyPath     = [keyPaths objectAtIndex:tag];
NSArray* subToValue = [toValues objectAtIndex:tag];
NSArray* subDuration = [durations objectAtIndex:tag];

NSEnumerator* keyPathsEnum = [subKeyPath objectEnumerator];
NSEnumerator* toValuesEnum = [subToValue objectEnumerator];
NSEnumerator* durationsEnum = [subDuration objectEnumerator];

NSString* keyPath;
NSNumber* toValue;
NSNumber* duration;

while ((keyPath = [keyPathsEnum nextObject]) && (toValue = [toValuesEnum nextObject]) && (duration = [durationsEnum nextObject])) {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:keyPath];

id offsetToValue;
if ([keyPath hasPrefix:@"position"]) {
//I removed the position animation, since animating the anchorPoint should suffice
} else if ([keyPath hasPrefix:@"anchorPoint"]) {
//This was when I used anchorPoint.x float value = [[subLayer valueForKeyPath:keyPath] floatValue] - ([toValue floatValue]/[[subLayer contents] size].width);
offsetToValue = [NSNumber valueWithPoint:CGPointMake(1.05, 0.5)];
keyPath = [keyPath substringToIndex:[keyPath length]-2];
} else {
offsetToValue = toValue;
}

...

animation.toValue = offsetToValue;
animation.duration = [duration floatValue];
animation.fillMode = kCAFillModeForwards;
animation.repeatCount = INFINITY;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

[subLayer addAnimation:animation forKey:keyPath];

//update the model

}

我尝试为“anchorPoint.x”keyPath 设置动画,结果相同 :(

最后一点,我正在编写一个 cocoa 应用程序,但是在 cocoa 和 cocoa touch 上动画 X 值应该完全相同。

最佳答案

你不会相信这个(就好像我从一开始就和你坐在一起一样)..

动画位置和旋转在没有设置 fromValue 的情况下工作正常。但是,动画 anchor 需要我将 anchor fromValue 设置为初始值!

animation.fromValue = [subLayer valueForKeyPath:keyPath];

关于ios - 动画 CALayer anchorPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10510616/

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