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

查看:20
本文介绍了在 -[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: 和 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;

在我的一个图层中插入或更改子图层时禁用淡入/淡出动画,以及图层大小和内容的变化.我相信 contents 键是您正在寻找的键,以防止更新绘图时出现淡入淡出.

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.

Swift 版本:

let newActions = [
        "onOrderIn": NSNull(),
        "onOrderOut": NSNull(),
        "sublayers": NSNull(),
        "contents": NSNull(),
        "bounds": NSNull(),
    ]

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

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