views:

2491

answers:

2

When you scroll with the newer Apple Magic Mouse (at least on 10.6, I can't confirm any previous Mac OS) you get inertial scroll like scrolling on iPhone (that is, after a flick of the finger to scroll, it doesn't abruptly stop, but instead gradually slows down). This behaviour is "for free" with all NSScrollViews, it would appear.

There are exceptional cases, such as Tweetie for Mac (I've heard Tweetie was written with a custom Table View class that works akin to how UITableView works on iPhone).

My question is, how do the scroll views know how to do this inertial scrolling? My guess is the mouse [driver] repeatedly sends scroll events with a dampening scroll magnitude (or something like that) over the scroll period. But I'm not really sure how it works.

I am having some scrolling problems in my scrollview class and I'm trying to figure out why (obviously we don't have the source code to Tweetie to see why it doesn't get the proper scrolling), but just trying to better understand how it works in order to fix my own problems.

+3  A: 

NSScrollView doesn't know anything about the Magic Mouse. The inertial scrolling is performed by repeated scroll events.

You can override NSResponder's -scrollWheel: method and use NSLog to see how Magic Mouse scrolling differs from trackpad and traditional scrolling.

Traditional scrolling sets deltaX and deltaY to indicate the number of "lines" to scroll.

Smooth scrolling devices (Trackpads and the Magic Mouse) use deviceDeltaX and deviceDeltaY to indicate the number of pixels to scroll.

Additionally, Magic Mouse uses scrollPhase to indicate when an inertial scroll is in progress.

Note that deviceDeltaX and deviceDeltaY are private methods of NSEvent.

Darren
A: 

to opt out the momentum, add @"NO" for the Key @"AppleMomentumScrollSupported" at the very beginning of your app to the user defaults (see Magic Mouse Developer Release Notes). So you might also override it for Tweetie by adding this entry to your defaults of tweetue.

 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 NSDictionary *appDefaults = [NSDictionary dictionaryWithObject:@"NO" forKey:@"AppleMomentumScrollSupported"];
 [defaults registerDefaults:appDefaults];
mahal tertin