How to Make a Core Animation Layer Not Clickable

Core Animation Layers handle mouse clicks using the hitTest: and containsPoint: methods. It is common to have layers in the hierarchy that are simply visual effects and shouldn't be clickable. This is very easy to do.

In your CALayer subclass, simply override hitTest: and containsPoint: as follows:

- (CALayer *)hitTest:(CGPoint)thePoint {
    return nil;

- (BOOL)containsPoint:(CGPoint)p {
    return NO;

That's it! The layer can exist in the hierarchy of clickable layers without being itself clickable and interfering in the user input.

Question or Comment?