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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top