我如何设置NSScroll视图的默认位置?

时间:2022-11-18 18:08:48

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?

我在我的应用程序中遇到了NSScrollview的问题,因为它总是从窗口的底部开始。怎么能让它从顶部开始?

3 个解决方案

#1


11  

Try something like this:

尝试这样的事情:

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

#2


4  

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.

Scroll View编程指南中的解决方案,滚动到特定位置。您可以使用 - [NSView scrollPoint:]来设置剪辑视图的原点。

// 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];
}

#3


3  

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

如果您在NSScrollView中有自定义NSView子类,请尝试重写isFlipped:

- (BOOL)isFlipped
{
    return YES;
}

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

这会将视图的原点放在顶部,这应该使NSScrollView能够执行您想要的操作。

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

但是,它也会翻转视图中所有内容的坐标。

#1


11  

Try something like this:

尝试这样的事情:

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

#2


4  

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.

Scroll View编程指南中的解决方案,滚动到特定位置。您可以使用 - [NSView scrollPoint:]来设置剪辑视图的原点。

// 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];
}

#3


3  

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

如果您在NSScrollView中有自定义NSView子类,请尝试重写isFlipped:

- (BOOL)isFlipped
{
    return YES;
}

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

这会将视图的原点放在顶部,这应该使NSScrollView能够执行您想要的操作。

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

但是,它也会翻转视图中所有内容的坐标。