4

我在 NSWindow 中有一个 NSScrollView,但它似乎被禁用了。看起来它可以工作,但滚动条对鼠标或滚轮没有响应。

当我将完全相同的 NSScrollView 放在新 XCode 项目的窗口中时,它可以完美运行。我制作窗口的方式会阻止滚动工作。

我已经能够将其简化为这个例子:

//Make a window
NSWindow* myWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(300, 300, 300, 300)
                                       styleMask:NSTitledWindowMask
                                       backing:NSBackingStoreRetained
                                       defer:NO];

//Make a scroll view
NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300)];
[scrollview setHasVerticalScroller:YES];
[scrollview setAcceptsTouchEvents:YES];
[myWindow setContentView:scrollview];

//Add something big to the scroll view
NSButton* btn = [[[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 600, 900)] autorelease];
[scrollview setDocumentView:btn];

//Show the window
[NSApp arrangeInFront:self];
[myWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];

有任何想法吗?

4

1 回答 1

7

根据我刚刚做的一些实验,您的问题似乎与指定NSBackingStoreRetained. 文档说:

您不应使用此模式。它结合了 的限制NSBackingStoreNonretainedNSBackingStoreBuffered.

他们还说:

在 Mac OS X 10.5 及更高版本中,对保留窗口的请求将导致窗口系统创建一个缓冲窗口,因为这更好地匹配实际使用。

这似乎不准确;切换buffer:参数以NSBackingStoreBuffered使窗口和滚动视图的行为符合我的预期。(文档还说不要使用NSBackingStoreNonRetained,事实上,它似乎有类似的问题NSBackingStoreRetained。)

于 2011-07-01T23:22:24.137 回答