你如何立即移动CALayer

你如何立即移动CALayer

本文介绍了你如何立即移动CALayer(没有动画)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS应用中拖动CALayer。

I'm trying to drag a CALayer in an iOS app.

一旦我改变其位置属性,它就会尝试动画到新位置并闪烁所有在这个地方:

As soon as I change its position property it tries to animate to the new position and flickers all over the place:

layer.position = CGPointMake(x, y)

如何立即移动CALayers?我似乎无法理解核心动画API。

How can I move CALayers instantly? I can't seem to get my head around the Core Animation API.

推荐答案

您希望将呼叫包裹在以下内容中:

You want to wrap your call in the following:

[CATransaction begin];
[CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions];
layer.position = CGPointMake(x, y);
[CATransaction commit];

这篇关于你如何立即移动CALayer(没有动画)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:16