ReadCAAR.m

October 12, 2017 ยท View on GitHub

// 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