gpt4 book ai didi

cocoa - 为以编程方式创建的 IKImageBrowserView 添加垂直滚动

转载 作者:行者123 更新时间:2023-12-03 17:06:51 24 4
gpt4 key购买 nike

我想创建一个 Cocoa 库 Test.dylib,它使用 IKImageBrowserView 提供图标 View 。我无法在 nib 中创建 IKImageBrowserView,因为 dylib 不支持资源。因此,我以编程方式创建 IKImageBrowserView,如下所示:

IKImageBrowserView *browser = [[IKImageBrowserView alloc]initWithFrame:[self bounds]];
Datasource *ds = [[dataSource alloc]init];
[browser setDataSource:ds];
[browser setDelegate:ds];

但是,当项目多于可见区域时,应显示垂直滚动条,但这种情况不会发生。

如何支持以编程方式创建的 IKImageBrowserView 的滚动?

我已尝试以下方法,但没有取得积极结果:

NSScrollView *scroller = [[NSScrollView alloc]initWithFrame:[self bounds]];
[scroller addSubview:browser];

如何解决这个问题?

最佳答案

尝试将 IKImageBrowserView 放入 NSScrollView 中,您的做法是正确的。然而,不要使用addSubview(继承自NSView),而是使用setDocumentView…

NSScrollView *scroller = [[NSScrollView alloc]initWithFrame:[self bounds]];
[scroller setDocumentView:browser];
[scroller setHasVerticalScroller:YES];

Scroll View Programming Guide其中有一些很好的信息...

NSScrollView instances provide scrolling services to its document view. This is the only view that an application must provide a scroll view. The document view is responsible for creating and managing the content scrolled by a scroll view.

关于cocoa - 为以编程方式创建的 IKImageBrowserView 添加垂直滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5428320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com