SVGKLayer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #import <QuartzCore/QuartzCore.h>
  2. #import "SVGKit.h"
  3. /**
  4. * SVGKLayer: this is the "low level" equivalent of SVGKImageView, and allows you to perform e.g. CoreAnimation on the individual elemetns / layers
  5. within an SVG Image.
  6. NB: this class is MORE COMPLEX than SVGKImageView, and requires you to DO MORE WORK. It is also LOWER PERFORMANCE for basic usage - it expects
  7. YOU to do the work if you want caching, OpenGL acceration, etc. To give you total access to the rendering, we have to disable all the performance
  8. optimizations coded into SVGKImageView
  9. Basic usage:
  10. - NOTE: most of the time, you DO NOT WANT this class, you instead want to use SVGKImageView, which does lots more work for you.
  11. - Usage as per CALayer:
  12. - SVGKLayer *skl = [[SVGKLayer alloc] init];
  13. - skl.SVGImage = [SVGKImage imageNamed:@"image.svg"];
  14. - [self.view.layer addSublayer: skl];
  15. Advanced usage:
  16. - Note that EVERY ELEMENT in the original SVG is rendered as a SEPARATE CALayer - you can access all the layers by name, and animate them
  17. - ...c.f. the demo project (currently "iOS-Demo.xcodeproj" and how we animate the Monkey.svg file, wobbling its head
  18. Performance:
  19. - NOTE: to give you full control of the layers, I had to delete the "auto-re-rasterize at highest pixel detail". I cannot find a way to make that work with Apple's hierarchy of CALayers (it only works when manually blitting). If anyone can figure this out, we'd all be extermely grateful!
  20. - NOTE: the way this works - adding all layers individually - can have complex effects on performance. Some SVG files will render surprisingly fast, others surpisingly slow.
  21. ... you MUST understand Apple's complete rendering system in detail to undertand what's going on (not recommended for beginners!)
  22. - NOTE: you MUST NOT call SVGKImage.CALayerTree.transform - that will have unexpected side-effects, because of Apple's implementation
  23. */
  24. @interface SVGKLayer : CALayer
  25. @property(nonatomic,strong) SVGKImage* SVGImage;
  26. @property(nonatomic) BOOL showBorder; /**< mostly for debugging - adds a coloured 1-pixel border around the image */
  27. @property (nonatomic, strong) NSDate* startRenderTime, * endRenderTime; /**< for debugging, lets you know how long it took to add/generate the CALayer (may have been cached! Only SVGKImage knows true times) */
  28. @end