NSWindow中的NSScrollView

NSWindow中的NSScrollView

本文介绍了NSWindow中的NSScrollView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an NSScrollView inside an NSWindow, but it seems to be disabled. It looks like it would work, but the scrollbars are unresponsive to the mouse or the scroll wheel.

何时我将完全相同的NSScrollView放在新XCode项目的窗口中,它的工作原理非常完美。我制作窗口的方式阻止了滚动工作。

When I put the exact same NSScrollView inside a window on a new XCode project, it works perfect. There is something about the way I am making the window that is preventing the scroll from working.

我已经可以将其简化为以下示例:

I've been able to simplify it to this example:

//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 。文档说:

Your problem, based on some experimentation I just did, seems to be with specifying NSBackingStoreRetained. The docs say:

他们还说:

这将导致窗口系统创建一个缓冲窗口,因为它与实际使用更好地匹配。将 buffer:参数切换为 NSBackingStoreBuffered 使窗口和滚动视图的行为符合我的预期。 (文档还说不要使用 NSBackingStoreNonRetained ,实际上,它似乎有与 NSBackingStoreRetained 类似的问题。)

This does not seem to be accurate; switching the buffer: argument to NSBackingStoreBuffered made the window and scroll view behave as expected for me. (The docs also say not to use NSBackingStoreNonRetained, and indeed, it seemed to have problems similar to NSBackingStoreRetained.)

这篇关于NSWindow中的NSScrollView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:15