gpt4 book ai didi

objective-c - NSWindow 中的 NSScrollView

转载 作者:太空狗 更新时间:2023-10-30 04:01:26 26 4
gpt4 key购买 nike

我在 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];

有什么想法吗?

最佳答案

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

You should not use this mode. It combines the limitations of NSBackingStoreNonretained with the memory use of NSBackingStoreBuffered.

他们还说:

In Mac OS X 10.5 and later, requests for retained windows will result in the window system creating a buffered window, as that better matches actual use.

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

关于objective-c - NSWindow 中的 NSScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6553883/

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