NSScrollView 内的自定义 NSSroller

发布于 2024-10-20 21:34:33 字数 1131 浏览 2 评论 0 原文

我在 NSScrollView 中嵌入了 IKImageBrowserView。

我正在尝试实现滚动条,就像我们在 Lion 或 Sparrow 和 Reeder 等其他应用程序中看到的那样。我希望我的滚动条能够覆盖内容。

因此,我遇到的唯一问题是内容超出了滚动条而不是滚动条。

我知道我可以使用 NSScrollView 的 -tile 方法来排列不同的部分,但我不知道如何使用它来达到我的目的。

编辑:这是我的-tile中的代码:

- (void)tile
{
    [super tile];

    // We move the scroll to be just below the scrollView
    NSScroller *verticalScroller = [self verticalScroller];
    NSRect verticalScrollerFrame = [verticalScroller frame];
    verticalScrollerFrame.origin.x -= 117.0;
    [verticalScroller setFrame:verticalScrollerFrame];

    // We expand the scrollview to embrace the whole window
    NSRect scrollViewFrame = [self frame];
    scrollViewFrame.size.width = 655.0;
    [self setFrame:scrollViewFrame];

}

它看起来像这样:

有谁知道为什么滚动条的内容位于内容视图下方?或者有例子吗?

我已经看过这个主题: Overlay NSScroller over content 以及很多其他主题,但没有找到一个答案。

感谢您的帮助!

I have a IKImageBrowserView embedded inside an NSScrollView.

I'm trying achieve scroll bars like those we can see in Lion or other apps like Sparrow and Reeder. I would like my scroll bars to go over the content.

So fare the only problem I have is that the content goes over the scroll bar instead of going under.

I know that I can play with the -tile methode of the NSScrollView to arrange the different pieces but I don't know how I can use it to my purpose.

EDIT : This is the code in my -tile :

- (void)tile
{
    [super tile];

    // We move the scroll to be just below the scrollView
    NSScroller *verticalScroller = [self verticalScroller];
    NSRect verticalScrollerFrame = [verticalScroller frame];
    verticalScrollerFrame.origin.x -= 117.0;
    [verticalScroller setFrame:verticalScrollerFrame];

    // We expand the scrollview to embrace the whole window
    NSRect scrollViewFrame = [self frame];
    scrollViewFrame.size.width = 655.0;
    [self setFrame:scrollViewFrame];

}

Here is what it looks like:

preview

Does anyone know why the content the scroll bars go under the content view? Or have an example?

I've already looked at this topic : Overlay NSScroller over content and a lot of others without finding an answer.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2024-10-27 21:34:33

好吧,我想我找到了问题。

NSRect scrollViewFrame = [self frame];
scrollViewFrame.size.width = 655.0;
[self setFrame:scrollViewFrame];

在此块中,我使用[self frame]来获取NSClipView contentFrame而不是[[self contentView]frame]

它应该看起来像这样。

NSRect scrollViewFrame = [[self contentView] frame];
scrollViewFrame.size.width = 655.0;
[[self contentView] setFrame:scrollViewFrame];

我还没有尝试过,但我很确定这就是问题所在。

Ok I think I found the problem.

NSRect scrollViewFrame = [self frame];
scrollViewFrame.size.width = 655.0;
[self setFrame:scrollViewFrame];

In this block I'm using [self frame] to get the NSClipView contentFrame instead of [[self contentView] frame].

It should look like this.

NSRect scrollViewFrame = [[self contentView] frame];
scrollViewFrame.size.width = 655.0;
[[self contentView] setFrame:scrollViewFrame];

I havn't tried it yet but I pretty sure this is the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文