Skip to content
This repository was archived by the owner on Jul 1, 2022. It is now read-only.

Collection view's hitTest method eats clicks intended for subviews #3

@tsfischer

Description

@tsfischer

I am attempting to use KDXCollectionView as a grid of subviews which contain sub controls such as buttons. I was initially stumped as to why my buttons were not getting click events, but I tracked it down to the KDXCollectionView's override implementation of hitTest.

I believe what you really want to do is call the super's hitView, and only eat the clicks if they are not intended for a subview. The following code fixes it for me, although since I'm pulling this in as a Cocoapod it gets a little messy for me to change.

  • (NSView *)hitTest:(NSPoint)aPoint
    {
    NSView *hitView = [super hitTest:aPoint];

    if (!hitView && NSMouseInRect(aPoint, [self visibleRect], [self isFlipped])) {
    return self;
    }

    return hitView;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions