更改CAShapeLayer而不使用动画 [英] Change CAShapeLayer without Animation

查看:115
本文介绍了更改CAShapeLayer而不使用动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 CAShapeLayer strokeEnd 属性,而不使用默认动画,完全没有动画。

I want to set the strokeEnd property of a CAShapeLayer without the default animation, with no animation at all. I've looked around to try to find how to do this but everything seems to be about how to animate properties.

推荐答案

在这个例子中,核心动画术语,动画的更通用术语是动作。例如,您可以看到 CAAnimation 符合 CAAction 协议。您还可以看到禁用动画时使用的术语动作(禁用动画)。

In Core Animations terminology, a more general term for an animation is an "action". You can for example see that the CAAnimation conforms to the CAAction protocol. You also see the terminology "action" used when disabling them (disabling the animations).

有许多不同的方法可以更改图层的操作。其中许多文档在关于 CALayer actionForKey:文档的讨论摘录如下)。其中一些在子类化时更相关(您还可以覆盖子类中的 actionForKey:,为新的键添加更多隐式动作。

There are many different ways of changing the actions of a layer. Many of them are documented pretty well in the discussion of the actionForKey: documentation on CALayer (excerpt below). Some of them are more relevant when subclassing (and you can also override actionForKey: in your subclass to add more implicit actions for new keys.


此方法按以下顺序搜索图层的关联操作:

This method searches for the layer’s associated actions in the following order:


  1. 层有一个委托,并且委托实现访问层的过滤器方法,层调用该方法。委托必须执行以下操作之一:


    • 返回

    • li>如果不处理操作,则返回 NSNull 对象,并且搜索应该终止。
  1. If the layer has a delegate and that delegate implements the Accessing the Layer’s Filters method, the layer calls that method. The delegate must do one of the following:
    • Return the action object for the given key.
    • Return nil if it does not handle the action.
    • Return the NSNull object if it does not handle the action and the search should be terminated.


动画(两种不同,因为它们用于稍微不同的东西):

The two ways that are most interesting when you want to disable animation are (two different because they are used for slightly different things):


  1. 使用 code>(以上未提及)

  2. @设置 [NSNull null] 键入操作字典(上面的第2条)



禁用操作



使用事务来禁用动画是很好的,当你暂时想禁用动作完全为一些不同的属性,而仍然有动画在其他地方。在代码中它看起来像这样:

Disabling actions

Using a transaction to disable animations is good when you temporarily want to disable actions completely for a number of different properties while still having animations everywhere else. In code it looks something like this:

[CATransaction begin];
[CATransaction setDisableActions:YES];
// change your property here 
yourShapeLayer.strokeEnd = 0.7;
[CATransaction commit]; // animations are disabled until here...



更改操作字典



您可以通过修改图层操作字典来永久更改一个或多个键的默认动画。设置 [NSNull null] 意味着应该没有动画,并且图层应该停止在别处查找默认动画。您还可以使用此来添加可动画属性。使用操作字典删除动画看起来像这样:

Changing the actions dictionary

You can permanently change the default animation for one or more keys by modifying the layers action dictionary. Setting [NSNull null] means that there should be no animation and that the layer should stop looking elsewhere for a default animation. You can also use this to add animatable properties. Removing an animation using the action dictionary looks something like this:

yourShapeLayer.actions = @{@"strokeEnd": [NSNull null]};
yourShapeLayer.strokeEnd = 0.7; // this won't have an animation

这篇关于更改CAShapeLayer而不使用动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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