如果我将窗口大小调整为小于 Metal View ,我可以看到滚动条一秒钟,但我无法单击它们,它们也保持可见。你知道我该如何改变这种行为吗?我希望只要窗口小于 Metal View ,滚动条就可见且可点击。
nsview = gdk_quartz_window_get_nsview(window);
NSScrollView *scroll_view = [[NSScrollView alloc]initWithFrame: [nsview frame]];
[scroll_view setBorderType: NSNoBorder];
[scroll_view setHasVerticalScroller: YES];
[scroll_view setHasHorizontalScroller: YES];
[scroll_view setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
[nsview addSubview: scroll_view];
self->clip_view = [[DvFlippedClipView alloc]initWithFrame: [nsview frame]];
[scroll_view setContentView: self->clip_view];
self->mtk_view = [[MTKView alloc]initWithFrame: [nsview frame]
device: self->device];
self->mtk_view.framebufferOnly = YES;
self->mtk_view.autoResizeDrawable = NO;
self->mtk_view.translatesAutoresizingMaskIntoConstraints = NO;
self->mtk_view_delegate = [[DvMetalViewDelegate alloc] init: self->mtk_view];
self->mtk_view.delegate = self->mtk_view_delegate;
[scroll_view setDocumentView: self->mtk_view];
通过不同的回调,我执行以下操作:
[self->mtk_view setBounds:NSMakeRect(0, 0, width, height)];
[self->mtk_view setFrame:NSMakeRect(0, 0, width, height)];
self->mtk_view.drawableSize = CGSizeMake(width, height);
最佳答案
我昨天遇到了类似的问题,我怀疑奇怪的滚动器行为和完全缺乏滚动可能源于我怀疑您的问题所在。如果您还没有找到答案,希望它至少能启发您或其他人。
我的 View 层次结构如下所示:
问题是我将 MTKView 设置为 CenterTopViewController 的 View 属性,而不是边框 ScrollView 。这样做时,出于所有实际意图和目的,从层次结构中删除了 MTKView 并将其设置为使其 superview 属性指向所有这些内容所在的 Split View。 ScrollView 似乎不是响应者链的一部分,并且从未处理任何滚动事件(或至少不以任何有意义的方式)。
将 ScrollView 设置为 View Controller 的 View 属性可以解决所有问题。
附注 如果您对为什么 MTKView 上方有一个不必要的 View 感到困惑,这只是我在弄清楚之前几乎绝望地试图发现问题的结果。我还没来得及修复它。
关于cocoa - 如何使 NSScrollView 内的 MTKView 显示滚动条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56427857/