cocoa - 删除 CALayer 内容属性的插值

标签 cocoa core-animation calayer

重新提问:

当您为内容键添加动画时,显然会触发 CATransitionAnimation,它将原始内容属性淡入动画值数组中的第一个值,从而导致 0.25 秒的淡入淡出。而且看起来很糟糕!我已经使用此处讨论的所有方法抑制了每个可动画属性(通过委托(delegate)将空动画返回到 Action 字典中,使用 CATransaction),但这些似乎都不是针对这个特定的过渡动画。

alt text

我一直在研究什么属性(property)可能造成这种情况,但无法弄清楚。

我需要抑制向内容键添加动画时发生的过渡动画。

我实在是太不知所措了,所以我就把正在添加的关键帧动画放上来给大家看看。我想也许我在这里做错了什么?请注意,该数组只是 6 个 CGImageRef(动画帧)的数组。

+ (CAKeyframeAnimation *)moveLeftAnimation {

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
animation.values = [NSArray arrayWithArray:[Setzer walkingLeftSprite]];
animation.duration = 0.5f;
animation.keyTimes = [NSArray arrayWithObjects:
                      [NSNumber numberWithFloat:0.0], 
                      [NSNumber numberWithFloat:0.2], 
                      [NSNumber numberWithFloat:0.4],
                      [NSNumber numberWithFloat:0.6],
                      [NSNumber numberWithFloat:0.8],
                      [NSNumber numberWithFloat:1.0],
                      nil];
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
return animation;

}

另外,我有一个动画可以在 Sprite 的 Action 字典中处理位置键:

+ (CABasicAnimation *)moveAnimation {

CABasicAnimation *moveAnimation = [CABasicAnimation animation];
moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
moveAnimation.duration = 0.5f;

return moveAnimation;

}

我在想,当您更改图层的位置时,也许会发生这种转变?我不知道...

请帮忙!这让我发疯!

最佳答案

您可以按照我在this answer中描述的方式做一些事情,我通过在该图层的 actions 字典中设置适当的值来禁用各种图层属性的隐式动画。

就你而言,我相信类似的事情

NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
                                   [NSNull null], @"contents",
                                   nil];
layer.actions = newActions;
[newActions release];

应阻止图层的 contents 属性的隐式动画,直到您显式为其设置动画。

关于cocoa - 删除 CALayer 内容属性的插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4334330/

相关文章:

objective-c - 如何从字体文件中获取字体名称?

objective-c - 为什么 alloc 和 init 在 Objective-C 中分开调用?

ios - 坠落效果 - 在 z 轴上移动

cocoa - 绘制层 :inContext: draws background over content when using Layer-Hosting NSView

ios - 应用图层蒙版后我的图像按比例缩小

ios - 基于路径的 mask ,具有很好的抗锯齿效果

iphone - 使用 CALayers 的圆形 UIView - 只有一些角落 - 如何?

objective-c - 以编程方式更改 OSX 中的用户帐户图像

iphone - @selector 中的参数

iphone - 加载 View 时导航栏跳跃