无法禁用CALayer>>> removeFromSuperlayer的动画 [英] Unable to disable animation of CALayer>>removeFromSuperlayer

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

问题描述

我希望在不设置动画的情况下从其上层删除CALayer。这里发生的是将图层动画化到一个位置,并且效果很好,但是当动画停止时,将执行此代码,该代码将图层返回到其起始位置,然后淡出。大概然后将其从上层移除。如何停止对-removeFromSuperlayer设置动画?此处列出的代码对于未注释且未注释的所有变体,包括事务或没有事务,具有相同的行为。我想念什么?

I wish to remove a CALayer from its superlayer without animating. What happens here is the layer animates to a position, works great, when however the animation stopped, this code is executed, which returns the layer to its start position, and fades out; presumably then gets removed from the superlayer. How may it be stopped from animating -removeFromSuperlayer ? The code listed here has the same behavior for all variations of the included comments being uncommented and not uncommented, Transaction or no transaction. What am I missing?

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    //[self setHidden: YES];

    //[CATransaction flush];
    [CATransaction begin];
    [CATransaction setValue:(id)kCFBooleanTrue
                     forKey:kCATransactionDisableActions];
    //[CATransaction setDisableActions: YES];
    //[CATransaction setAnimationDuration: 0];
    [self removeFromSuperlayer];
    [CATransaction commit];
}

我一直在搜索,此代码与我的代码没有什么不同已找到。

I have been searching around, and this code is not any different from what I have found.

推荐答案

您可以通过在超级图层上设置操作字典为涉及子图层的动画返回null来禁用隐式动画(类似于我的回答在这里):

You can disable the implicit animation by setting the actions dictionary on the superlayer to return null for animations involving sublayers (similar to my answer here):

NSMutableDictionary *newActions = [[NSMutableDictionary alloc] initWithObjectsAndKeys:[NSNull null], @"sublayers", nil];
superlayer.actions = newActions;
[newActions release];

您可能还需要覆盖图层(而非超级图层)的onOrderOut操作,以防止出现这种情况。我会在链接的答案中说明如何做到这一点。

You may also need to override the layer's (not the superlayer's) onOrderOut action to prevent this. I show how to do that in the linked answer.

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

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