CALayerWithChildHitTest.m 834 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. //
  2. // CALayerWithChildHitTest.m
  3. // SVGKit
  4. //
  5. //
  6. #import "CALayerWithChildHitTest.h"
  7. @implementation CALayerWithChildHitTest
  8. - (BOOL) containsPoint:(CGPoint)p
  9. {
  10. BOOL boundsContains = CGRectContainsPoint(self.bounds, p); // must be BOUNDS because Apple pre-converts the point to local co-ords before running the test
  11. if( boundsContains )
  12. {
  13. BOOL atLeastOneChildContainsPoint = FALSE;
  14. for( CALayer* subLayer in self.sublayers )
  15. {
  16. // must pre-convert the point to local co-ords before running the test because Apple defines "containsPoint" in that fashion
  17. CGPoint pointInSubLayer = [self convertPoint:p toLayer:subLayer];
  18. if( [subLayer containsPoint:pointInSubLayer] )
  19. {
  20. atLeastOneChildContainsPoint = TRUE;
  21. break;
  22. }
  23. }
  24. return atLeastOneChildContainsPoint;
  25. }
  26. return NO;
  27. }
  28. @end