禁用CALayer隐式动画 [英] Disabling CALayer implicit animations

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

问题描述

下面的类试图在 CALayer 更改属性后阻止任何隐式动画的发生。

The class below is attempting to stop any implicit animations from occurring when a CALayer has a property changed.

// NoImplicitAnimations.h

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>

@interface NoImplicitAnimations : NSObject

- (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key;

@end



// NoImplicitAnimations.m

#import "NoImplicitAnimations.h"

@implementation NoImplicitAnimations

- (id<CAAction>) actionForLayer:(CALayer *)layer forKey:(NSString *)key {
  return (id)[NSNull null];
}

@end

我导入 NoImplicitAnimations.h 在我的Swift桥接标头中。

I import NoImplicitAnimations.h in my Objective-C to Swift bridging header.

我创建了一个全局常量 let _noImplicitAnimations = NoImplicitAnimations()

I create a global constant let _noImplicitAnimations = NoImplicitAnimations().

我像这样扩展 CALayer 类:

extension CALayer {
  func noImplicitAnimations () {
    delegate = _noImplicitAnimations
  }
}

现在出现了问题。创建 myLayer 之后,我立即使用 myLayer.noImplicitAnimations()。但是,隐式动画仍在发生。

Now comes the problem. I use myLayer.noImplicitAnimations() right after I create myLayer. Yet, implicit animations are still happening.

推荐答案

没关系。这确实有效。我在错误的 CALayer 上进行了测试。我的坏人!

Nevermind. This actually does work. I was testing it on the wrong CALayer. My bad!

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

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