如何禁用CALayer的隐式动画? [英] How to disable CALayer implicit animations?

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

问题描述

它快把我逼疯了!我工作的绘图应用程序。比方说,我在的UIView 称为表工作。

It's driving me crazy! I am working on a drawing application. Let's say I am working on a UIView called sheet.

我添加了一些子层这个观点( [sheet.layer addSublayer:...] ),然后我要画到他们。要做到这一点我创建一个 CGImageRef ,并把它变成层的内容。但它的动画,我不希望出现这种情况。

I am adding some sublayers to this view ([sheet.layer addSublayer:...]) and then I want to draw into them. To do so I am creating a CGImageRef and putting it into the layer's contents. But it's animated and I don't want that.

我什么都试过:


  • removeAnimationForKey:

  • removeAllAnimations

  • 设置操作字典

  • 使用actionlayer 代表

  • [CATransaction setDisableAnimations:YES]

  • removeAnimationForKey:
  • removeAllAnimations
  • set the actions dictionary
  • using the actionlayer delegate
  • [CATransaction setDisableAnimations:YES]

它似乎是正确的。我不明白为什么这层仍是动画; _;结果
难道我做错了什么?有一个秘密的方式?

It's seems correct. I don't understand why this layer is still animated ;_;
Am I doing something wrong? Is there a secret way?

推荐答案

您必须通过在CATransaction包裹你的code明确禁用动画

You have to explicitly disable animations by wrapping your code in a CATransaction

[CATransaction begin];
[CATransaction setValue:(id)kCFBooleanTrue
                 forKey:kCATransactionDisableActions];
layer.content = someImageRef;
[CATransaction commit];

随意张贴一些code。

Feel free to post some code.

最好的,

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

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