reflectScrolledClipView confusion

Discussion in 'Mac Programming' started by GregX999, May 3, 2009.

  1. GregX999 macrumors newbie

    GregX999

    Joined:
    Apr 5, 2009
    #1
    Ok, so I dragged a Scroll View (NSScrollView) into my IB window, selected the inner NSView, and changed its class to a custom class (which I named "MapView").

    I also made a button that scrolls the map upwards (northwards) by 20 pixels.

    The button works fine, but the vertical scrollbar, of course, doesn't update. I know I need to use reflectScrolledClipView to do that.

    But I'm totally confused... :(

    From inside the "moveNorth" method of the MapView class, how do I call it?
    [scrollView reflectScrolledClipView:self]; ???
    [scrollView reflectScrolledClipView:[scrollView contentView]]; ???
    [self reflectScrolledClipView:[scrollView contentView]]; ???

    None of those seem to work.

    My problem is I don't understand what the docs mean when they mention "aClipView". Is the clip view the view inside the scrollbar (aka MapView)? Or is it another view that's inside the Scroll View that contains MapView?

    Here's my scrollNorth method (as it is now):
    Code:
    - (void)scrollNorth
    {
    	NSRect bounds = [self bounds];
    	[self setBoundsOrigin:NSMakePoint(bounds.origin.x, bounds.origin.y + 20)];
    	NSView *scrollView = [self enclosingScrollView];
    	[scrollView reflectScrolledClipView:self];
    }
    
    Also, by using setBoundsOrigin, the map "jumps" 20 pixels, is there a single command that will make it smoothly scroll those 20 pixels?

    Thanks for any help you can give - even if just a hint or two... :eek:
    Greg
     
  2. kpua macrumors 6502

    Joined:
    Jul 25, 2006
    #2
    Careful. You may or may not have set up your scroll view wrong. The best way to make a scroll view containing a custom view is to first create the custom view, then choose "enclose in scroll view" from the menu.

    The problem is, you may have replaced your clip view, instead of properly setting the document view. A scroll view's single subview (besides the NSScrollers) is the NSClipView, which is responsible for, well, clipping the contents. The document view is what is being clipped.

    If I remember correctly, when the scroll view is set up correctly, the NSClipView should receive a notification whenever the size of the document view changes, and will call reflectScrolledClipView for you. If not, then the correct call from you document view would be:

    Code:
    [[self enclosingScrollView] reflectScrolledClipView:[self superview]];
    I think your best bet for smoothly scrolling would be to animate your bounds/frame change.
     

Share This Page