【发布时间】:2025-12-22 10:50:06
【问题描述】:
如果我将窗口大小调整为小于金属视图,我可以看到滚动条一秒钟,但我无法单击它们,它们也保持可见。你知道我怎样才能改变这种行为吗?只要窗口小于金属视图,我希望滚动条可见且可点击。
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);
【问题讨论】:
-
出于好奇,您为什么将
MTKView的translatesAutoresizingMaskIntoConstraints设置为false?删除那条线有帮助吗? -
我想我添加它是我解决此问题的尝试之一。删除该行不会改变问题。
-
滚动本身是否真的有效(使用鼠标滚轮、多点触控鼠标或触控板)?
-
它没有,滚动条只是在调整窗口大小期间出现一秒钟然后它们消失并且在边框周围移动鼠标不会显示滚动条,直到我再次调整大小...
标签: cocoa metal nsscrollview