Skip to content

Instantly share code, notes, and snippets.

@insidegui
Created October 12, 2017 21:19
Show Gist options
  • Save insidegui/59a7264a99d794d41236008fcf1e32d3 to your computer and use it in GitHub Desktop.
Save insidegui/59a7264a99d794d41236008fcf1e32d3 to your computer and use it in GitHub Desktop.
// This only has to be called once in the application's lifetime
[NSKeyedUnarchiver setClass:[CALayer class] forClassName:@"KFVectorLayer"];
[NSKeyedUnarchiver setClass:[CAShapeLayer class] forClassName:@"KFVectorFeatureLayer"];
[NSKeyedUnarchiver setClass:[CAShapeLayer class] forClassName:@"KFVectorAnimationLayer"];
[NSKeyedUnarchiver setClass:[CAShapeLayer class] forClassName:@"KFVectorGradientFeatureLayer"];
[NSKeyedUnarchiver setClass:[CAShapeLayer class] forClassName:@"KFVectorBitmapFeatureLayer"];
NSString *path = [[NSBundle mainBundle] pathForResource:@"NAME_OF_YOUR_FILE" ofType:@"caar"];
NSDictionary *archive = [NSKeyedUnarchiver unarchiveObjectWithData:[NSData dataWithContentsOfFile:path]];
CALayer *animLayer = archive[@"rootLayer"];
// You can now add animLayer as a sublayer of a view's layer,
// it's possible that the transform property will need to be changed
// to scale the animation layer to fit its superlayer,
// depending on the platform, you might need to flip the layer
// in the Y axis using another scale transform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment