Question

I have a trouble with a NSScrollview in my aplication because it always start at the bottom of the window. How could make it start in the top?

Was it helpful?

Solution

Try something like this:

NSPoint pointToScrollTo = NSMakePoint (  ,  );  // Any point you like.
[[scrollView contentView] scrollToPoint: pointToScrollTo];
[scrollView reflectScrolledClipView: [scrollView contentView]];

OTHER TIPS

A solution is given in the Scroll View Programming Guide, Scrolling to a Specific Location. You can use -[NSView scrollPoint:] to set the clip view's origin.

// A controller which has an outlet to the scroll view
- (void)awakeFromNib {

    // Not checking for flipped document view. See sample code.
    // New origin should be 
    // (documentView.frame.y + documentView.frame.height) - clipView.bounds.height
    NSPoint newOrigin = NSMakePoint(0, NSMaxY([[scrollView documentView] frame]) -
                                           [[scrollView contentView] bounds].size.height);
    [[scrollView documentView] scrollPoint:newOrigin];
}

If you have a custom NSView subclass inside the NSScrollView, try overriding isFlipped:

- (BOOL)isFlipped
{
    return YES;
}

This puts the view's origin at the top, which should make the NSScrollView do what you want.

However, it will also flip the coordinates of everything inside your view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top