How I set the default position of a NSScroll view? How I set the default position of a NSScroll view? xcode xcode

How I set the default position of a NSScroll view?


Try something like this:

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


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.