简体   繁体   English

如何更改CALayer的默认动画时间?

[英]How to change a CALayer's default animation time?

I use these code to move a CALayer: 我使用这些代码来移动CALayer:

CGPoint position = self.position;
position.x += 10;
position.y += 10;
self.position = position;

There is a default animation when i change the position of a layer without any animation call.This will cause lag on movement of a layer when i use these code in touchesMoved:withEvent:. 当我在没有任何动画调用的情况下更改图层的位置时,会有一个默认动画。当我在touchesMoved:withEvent:中使用这些代码时,这将导致图层移动滞后。

What i want to do is remove the default animation, and move the layer immediately so that it can responds to touch event quickly, just like the "center" property of UIView does. 我想要做的是删除默认动画,并立即移动图层,以便它可以快速响应触摸事件,就像UIView的“中心”属性一样。

What should i do? 我该怎么办? special thx! 特别的thx!

The other poster had the right idea, but didn't provide enough information. 另一张海报有正确的想法,但没有提供足够的信息。

If you want to change layer properties instantly, without animation, you need to put those changes inside a CATransaction where you disable actions: 如果要在没有动画的情况下立即更改图层属性,则需要将这些更改放在禁止操作的CATransaction中:

[CATransaction begin];
//[CATransaction setAnimationDuration: 1.0/30.0];
[CATransaction setDisableActions: TRUE];
//Put layer changes you want to take place without animation here.
[CATransaction commit];

Simply set 简单的设置

 [CATransaction setDisableActions:YES];

this will make the Layer move without lag 这将使Layer移动而不会延迟

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM