|ReleasedLast Release||Dec 2014|
Maintained by Unclaimed.
HTStateAwareRasterImageView is a rasterization system that caches rendered components based on state. The advantage over Core Animation's rasterization is that you only draw a component once for each unique state. Asynchronous drawing is also supported. Associated blog post at http://engineering.hoteltonight.com/asynchronous-state-aware-component-rasterizat
This library is dependent on the MSCachedAsyncViewDrawing class by Javier Soto of MindSnacks. The recommended installation method is cocoapods, which handles this dependency automatically. Add this line to your Podfile:
Start by conforming to the HTRasterizableView protocol. A simple example is provided in the demo project (HTExampleRasterizableComponent). The single required method is:
- (NSArray *)keyPathsThatAffectState;
This is used for two purposes:
Initialize a HTStateAwareRasterImageView and set the rasterizableView property to your HTRasterizableView, like this snippet from the demo project:
_rasterizableComponent = [[HTExampleRasterizableComponent alloc] init]; _stateAwareRasterImageView = [[HTStateAwareRasterImageView alloc] init]; _stateAwareRasterImageView.rasterizableView = _rasterizableComponent; _stateAwareRasterImageView.delegate = self; [self addSubview:_stateAwareRasterImageView];
If your component can take advantage of UIImage caps (fixed-size corners and stretchable center), these two methods are optional on the HTRasterizableView protocol:
- (UIEdgeInsets)capEdgeInsets; - (BOOL)useMinimumFrameForCaps;
You can specify if you want drawing to occur synchronously on the main thread:
@property (nonatomic, assign) BOOL drawsOnMainThread;
You can also turn off keypath observing if you want to manually regenerate images (use this for pre-rendering assets):
@property (nonatomic, assign) BOOL kvoEnabled; // For prerendering only - (void)regenerateImage:(HTSARIVVoidBlock)complete;
A delegate property is also available to let you know when it's regenerating an image, and when it gets a new image back:
@property (atomic, assign) id<HTStateAwareRasterImageViewDelegate> delegate;
For debugging purposes, the cache key is available through this method.
- (NSString *)cacheKey;
The demo project has four tabs:
The cache key used to define the state of your component is generated by the NSObject+HTPropertyHash category. It is important that the hash method produces a string that is unique to the state of your properties, but not TOO unique by including things like pointer values. The exception for CGColorRef in that category is made because we only want the RGBA values described, not the pointer value plus the RGBA values.
Tweet the author @jakejennings, and check out HotelTonight's engineering blog: http://engineering.hoteltonight.com
Also, check out HotelTonight's other iOS open source: