1
votes

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

1 Answers

0
votes

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