Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A caching Core Animation layer
Objective-C
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Example
.gitignore
README.md
YACachedLayer.h
YACachedLayer.m

README.md

YACachedLayer

A caching Core Animation layer

About

YACachedLayer is a CALayer subclass that can be used to cache complex draws to disk. It supports preloading on a background thread and caching different states of the same layer.

How to use

Include YACachedLayer in your project and use it as backing for a UIView.

@implementation CachedView

+ (Class)layerClass {
  return [YACachedLayer class];
}

- (id)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    ((YACachedLayer *)self.layer).cacheKey = @"MyCacheKey";
  }
  return self;
}

- (void)drawRect:(CGRect)rect {
  // do some drawing
}

@end

For more complex draws you can subclass it like you would any normal CALayer

@implementation ExampleLayer

- (void)drawInContext:(CGContextRef)context {
  [[UIColor redColor] setFill];
  CGContextFillRect(context, self.bounds);
}

@end

You can also implement formattedValueForKey: to cache multiple states of the layer. Check the source and the example project for more details.

Made by Johan Nordberg and licensed under the MIT-License

Something went wrong with that request. Please try again.