NSScrollView jumping to previous scroll when using scroll wheel

  • Hi,

    I suspect this is a matter of just missing some particular method
    call, but I'm out of ideas.

    I set up an NSScrollView object in IB containing a custom NSView. I
    want to programmatically scroll it horizontally back and forth. I can
    do this just fine (see code below), and I can scroll it using the
    scroll wheel just fine. But if I programmatically scroll it, and then
    use the scroll wheel, the scroll 'jumps' back to the place where I
    left off scrolling with the scroll wheel earlier.

    If I show the scroll view's horizontal scroll bar using [[self
    enclosingScrollView] setHasHorizontalScroller:YES]; , the location of
    the scroll I set programmatically is preserved, and everything works
    beautifully. If I set that to NO, which is the desired setting, the
    jumping occurs. How can I make it not jump?

    Here's my code.

    - (void) scrollIt
    NSScrollView *scrollView = [self enclosingScrollView];
    NSPoint currentScrollPosition=[[scrollView contentView] bounds].origin;
    NSLog(@"Before: %@", NSStringFromPoint(currentScrollPosition));

    // _scroll is an NSPoint that we set earlier, based on the current
    scroll plus our desired offset.
    [[scrollView documentView] scrollPoint:_scroll];

    // Turning this to YES or NO will deactivate or activate the bug
    [[self enclosingScrollView] setHasHorizontalScroller:YES];

    // This line verifies that the bug exists, and that we are actually
    jumping to the coordinates we scrolled
    // to when we last used the scroll wheel
    NSLog(@"After: %@", NSStringFromPoint([[[self enclosingScrollView]
    contentView] bounds].origin));

    // These were suggested, but didn't help
    //  [scrollView setHorizontalLineScroll:delta];
    //  [scrollView reflectScrolledClipView:[scrollView documentView]]; //
    didn't help
    //  [scrollView reflectScrolledClipView:[scrollView contentView]]; //
    didn't help
    //  [scrollView reflectScrolledClipView]; // didn't help


    Again, just having the scroller exist or not exist will toggle the
    bug. Is there something I'm missing?

    Thank you,
previous month january 2008 next month
  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 31      
Go to today