NSView -scrollPoint doesn't work with mouse wheel?

  • Hi,

    I scrolled one NSScrollView programmatically like following:

    NSPoint newPosition = NSMakePoint(0.0, 100.0);
    [[scrollView documentView] scrollPoint:newPosition];

    Ok, the scrollView did scroll to the new position, then I tried to
    continuously scroll down by using the mouse wheel, but the
    NSScrollView didn't work as I expected.
    It will return to the the point(0.0, 0.0) at first and start to scroll
    down rather then keep scrolling from point(0.0, 100.0).

    What's happening? It drives me crazy....

    Allen Dang
    <allengnr...>
  • On Dec 31, 2007, at 7:28 AM, Allen Dang wrote:
    > NSPoint newPosition = NSMakePoint(0.0, 100.0);
    > [[scrollView documentView] scrollPoint:newPosition];
    >
    > Ok, the scrollView did scroll to the new position, then I tried to
    > continuously scroll down by using the mouse wheel, but the
    > NSScrollView didn't work as I expected.
    > It will return to the the point(0.0, 0.0) at first and start to
    > scroll down rather then keep scrolling from point(0.0, 100.0).

    If the scroll view contains a text view, then use NSText's -
    (void)scrollRangeToVisible:(NSRange)range; method.

    For NSView, try -scrollRectToVisible: instead.  It is sort of the
    focal point for all scrolling operations in NSView.

    However, if the behavior persists then -- obviously -- something else
    is going on.    Are you setting the scrolling position from a thread,
    perchance?  That could cause confusion.

    b.bum
  • ÔÚ 2008-1-1£¬ÉÏÎç1:50£¬ Bill Bumgarner дµÀ£º
    > If the scroll view contains a text view, then use NSText's -
    > (void)scrollRangeToVisible:(NSRange)range; method.
    >
    > For NSView, try -scrollRectToVisible: instead.  It is sort of the
    > focal point for all scrolling operations in NSView.
    >
    > However, if the behavior persists then -- obviously -- something
    > else is going on.    Are you setting the scrolling position from a
    > thread, perchance?  That could cause confusion.
    >
    > b.bum

    I'm trying to implement a auto scroll down mechanism in a NSTextView.
    I use a NSTimer to trigger following code:

    - (void)startScroll:(NSTimer *)theTimer
    {
    //Start scroll.
    NSPoint currentScrollPosition=[[scrollView contentView] bounds].origin;
    NSPoint maxPosition = NSMakePoint(0.0,NSMaxY([[scrollView
    documentView] frame])
          -NSHeight([[scrollView contentView] bounds]));

    if (currentScrollPosition.y < maxPosition.y)
    {
      NSPoint newPosition = NSMakePoint(currentScrollPosition.x,
    currentScrollPosition.y + 1);

      [[scrollView documentView] scrollPoint:newPosition];
    }
    }

    Allen Dang
    <allengnr...>
previous month december 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
31            
Go to today