Created
August 23, 2011 00:40
-
-
Save sdrew/1164016 to your computer and use it in GitHub Desktop.
Mask based CALayer hit testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "CALayer_HitTestExtensions.h" | |
#import <objc/runtime.h> | |
static void *kHitMask; | |
@implementation CALayer (CALayer_HitTestExtensions) | |
- (NSUInteger)hitMask | |
{ | |
return([objc_getAssociatedObject(self, &kHitMask) unsignedIntegerValue]); | |
} | |
- (void)setHitMask:(NSUInteger)inHitMask | |
{ | |
objc_setAssociatedObject(self, &kHitMask, [NSNumber numberWithUnsignedInteger:inHitMask], OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
} | |
- (CALayer *)hitTest:(CGPoint)inPoint mask:(NSUInteger)inMask; | |
{ | |
CALayer *theLayer = [self hitTest:inPoint]; | |
while (theLayer != NULL && theLayer != self) | |
{ | |
if (inMask & theLayer.hitMask) | |
{ | |
return(theLayer); | |
} | |
theLayer = [theLayer superlayer]; | |
} | |
return(NULL); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment