Inertial scrolling and -ScrollWheel: on OS X

PROBLEM:

I have an NSScrollView. I use it to implement a custom "table view" with rows of data that are actually NSView. (Note: this is not an instance of NSTableView.)

When I scroll vertically (no horizontal scroll), I use the boundsChanged notification to add (as subviews of the scroll content of the ViewView) NSViews that become visible (those that have frames that intersect the scrollView document visible rect) and delete those that no longer visible (frames outside the scrollView visible rectangle).

The process works wonderfully, except when it comes to inertial scrolling. If I have a pointer to cell X, and I clicked the trackpad to scroll down FAST by inertia, cell X quickly leaves the visible rectangle and, as such, is removed from the scroll viewView. BUT that kills inertial scrolling. If I DO NOT delete cell X as a subview, then inertial scrolling works fine.

WHAT I NEED:

A way to save inertial scrolling when deleting an NSView when the cursor is higher than when the user started the scroll gesture.

WHAT I GOT:

I looked at the NSResponder method:

-scrollWheel:(NSEvent *)theEvent 

The default implementation passes scrollWheel to the next responder. Thus, I have subclassed NSScrollView and implemented this method to try to stop it from passing the scrollWheel event to individual sub-objects in the scroll viewview. Does not work.

So, I went into my NSViews (the ones I add to the contentView) and rewind scrollWheel to pass the event back to scrollView itself. Does not work.

I still get scrolling in both cases, but not with inertia.

Any ideas? Thanks!

+4
source share
1 answer

I did not do this exact thing in Cocoa, but I probably would have thought of simply reusing your NSView object as soon as it disappears from the visible rectangle, removing its subviews, and then changing its frame to scroll back to the visible rectangle at the top.

Obviously, you can do this by simply updating its frame and avoiding deleting it and re-adding it to NSScrollView.

0
source

All Articles