Disabling CALayer implicit animations

你离开我真会死。 提交于 2019-12-11 13:37:07

问题


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

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

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

I extend the CALayer class like so:

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

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

What am I doing wrong here?


回答1:


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



来源:https://stackoverflow.com/questions/25830050/disabling-calayer-implicit-animations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!