在 - [CALayer setNeedsDisplayInRect:]中禁用隐式动画 [英] Disabling implicit animations in -[CALayer setNeedsDisplayInRect:]

查看:133
本文介绍了在 - [CALayer setNeedsDisplayInRect:]中禁用隐式动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的-drawInContext:方法中有一个包含一些复杂绘图代码的图层。我正在尝试最小化我需要做的绘图量,因此我使用-setNeedsDisplayInRect:仅更新已更改的部分。这是非常好的工作。但是,当图形系统更新我的图层时,它会使用交叉淡入淡出从旧图像过渡到新图像。我希望它立即切换。

I've got a layer with some complex drawing code in its -drawInContext: method. I'm trying to minimize the amount of drawing I need to do, so I'm using -setNeedsDisplayInRect: to update just the changed parts. This is working splendidly. However, when the graphics system updates my layer, it's transitioning from the old to the new image using a cross-fade. I'd like it to switch over instantly.

我尝试使用CATransaction来关闭操作并将持续时间设置为零,并且都不起作用。这是我正在使用的代码:

I've tried using CATransaction to turn off actions and set the duration to zero, and neither work. Here's the code I'm using:

[CATransaction begin];
[CATransaction setDisableActions: YES];
[self setNeedsDisplayInRect: rect];
[CATransaction commit];

我应该使用不同的CATransaction方法(我也尝试过-setValue:forKey:with kCATransactionDisableActions,结果相同)。

Is there a different method on CATransaction I should use instead (I also tried -setValue:forKey: with kCATransactionDisableActions, same result).

推荐答案

您可以通过设置图层上的操作字典来返回 [NSNull null] 作为相应键的动画。例如,我使用

You can do this by setting the actions dictionary on the layer to return [NSNull null] as an animation for the appropriate key. For example, I use

NSDictionary *newActions = @{
    @"onOrderIn": [NSNull null],
    @"onOrderOut": [NSNull null],
    @"sublayers": [NSNull null],
    @"contents": [NSNull null],
    @"bounds": [NSNull null]
};

layer.actions = newActions;

在我的某个图层中插入或更改子图层时禁用淡入/淡出动画作为图层大小和内容的变化。我相信内容键是您要查找的密钥,以防止更新图纸上的交叉淡入淡出。

to disable fade in / out animations on insertion or change of sublayers within one of my layers, as well as changes in the size and contents of the layer. I believe the contents key is the one you're looking for in order to prevent the crossfade on updated drawing.

这篇关于在 - [CALayer setNeedsDisplayInRect:]中禁用隐式动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆