Horizontal-only scrolling

  • Hi!

    I have a view that's inside an NSScrollView. My view isn't very tall,
    and can easily fit vertically in the scroll view. However, the view
    can be very wide, that's why it's in the scroll view in the first place.

    What I'd like is that normal scroll wheel events would cause the
    scroll view to scroll horizontally (the only way it can scroll).
    Currently the user has to hold down the shift key to achieve
    horizontal scrolling (or use Mighty Mouse or something, I haven't
    tested, I don't like or use the Mighty Mouse :).

    Does anyone know an elegant solution to either for converting verical
    scroll events to horizontal or otherwise force the scroll view to
    always scroll horizontally, even when istructed to scroll vertically?

    -scrollWheel: would be nice, if I could convert the NSEvent to
    horizontal scrolling from vertical scrolling, but NSEvent API doesn't
    seem to make that possible (maybe by subclassing NSEvent?).

    Thanks for any help!

    Regargs,

    Petteri Kamppuri
  • On Nov 20, 2007, at 7:23 AM, Petteri Kamppuri wrote:

    > -scrollWheel: would be nice, if I could convert the NSEvent to
    > horizontal scrolling from vertical scrolling, but NSEvent API
    > doesn't seem to make that possible (maybe by subclassing NSEvent?).

    Hej,

    Perhaps subclass NSScrollView and implement this type of override:

    - (void) scrollWheel:(NSEvent *) event
    {
      NSPoint scrollPoint = [[self contentView] bounds].origin;
      scrollPoint.x += rintf([event deltaY]);
      scrollPoint.y += rintf([event deltaX]);
      [[self documentView] scrollPoint: scrollPoint];
    }

    FYI: This is a fantastic guide to NSScrollView:

    <http://developer.apple.com/documentation/Cocoa/Conceptual/NSScrollViewGuide
    /index.html
    >

    j o a r
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today