12

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

4

3 回答 3

12

尝试这样的事情:

NSPoint pointToScrollTo = NSMakePoint (  ,  );  // Any point you like.
[[scrollView contentView] scrollToPoint: pointToScrollTo];
[scrollView reflectScrolledClipView: [scrollView contentView]];
于 2011-04-29T18:57:39.467 回答
4

Scroll View Programming Guide, Scrolling to a specific Location中给出了解决方案。您可以使用-[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];
}
于 2011-04-29T18:56:59.450 回答
3

如果您在 NSScrollView 中有自定义 NSView 子类,请尝试覆盖isFlipped

- (BOOL)isFlipped
{
    return YES;
}

这将视图的原点放在顶部,这应该使 NSScrollView 做你想做的事。

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

于 2011-07-03T12:25:37.580 回答