Back again and have a different question with the same function that I posted before:
- (AIEnemyUnit *) hitTestForEnemyUnit:(CGPoint)where {
CALayer * layer = [self hitTest:where];
while (layer) {
if ([layer isKindOfClass:[AIEnemyUnit class]]) {
return (AIEnemyUnit *)layer;
} else {
layer = layer.superlayer;
}
}
return nil;
}
I have a bomb that the user drags on top of the enemy so that it is displayed directly above the AIEnemyUnit. For this bomb I implemented the CALayer -containsPoint:
to return NO during a drag to allow -hitTest: to pass through the layer. Basically this type of hit testing was working fine with these "pass-through" layers as long as I only used CGImageRef contexts. However once I started implementing sublayers for additional effects on the bomb, -hitTest:
immediately broke. It was obvious, the new layers were capturing the -hitTest:
. I tried implementing the same technique by overloading -containsPoint:
for these layers, but it was still returning the bomb's generic CALayer subclass instead of passing through.
Is there a better way?