I like to create a Cocoa window without any chrome whatsoever. The only thing the user should see is what I draw.
我喜欢创建一个没有任何铬的Cocoa窗口。用户唯一应该看到的是我画的东西。
I've discovered I can create a custom NSView but does this have to be in an NSWindow to display? If not, how can I display it without putting it in an NSWindow? If it does have to be in an NSWindow, how do I stop the window from drawing a title bar and other chrome?
我发现我可以创建一个自定义的NSView,但这必须在NSWindow中显示吗?如果没有,我如何在不将其放入NSWindow的情况下显示它?如果它必须在NSWindow中,如何阻止窗口绘制标题栏和其他chrome?
2 个解决方案
#1
#2
I've discovered I can create a custom NSView but does this have to be in an NSWindow to display?
我发现我可以创建一个自定义的NSView,但这必须在NSWindow中显示吗?
Yes.
If it does have to be in an NSWindow, how do I stop the window from drawing a title bar and other chrome?
如果它必须在NSWindow中,如何阻止窗口绘制标题栏和其他chrome?
Use NSBorderlessWindowMask when you create your window. (Assuming you aren't using a custom subclass of NSWindow, this means not creating the window instance in a nib. If you want to lay out your view hierarchy in a nib, do that in a top-level custom view, then load the nib and set that view as the window's content view.)
创建窗口时使用NSBorderlessWindowMask。 (假设您没有使用NSWindow的自定义子类,这意味着不在nib中创建窗口实例。如果要在nib中布置视图层次结构,请在*自定义视图中执行此操作,然后加载nib并将该视图设置为窗口的内容视图。)
#1
#2
I've discovered I can create a custom NSView but does this have to be in an NSWindow to display?
我发现我可以创建一个自定义的NSView,但这必须在NSWindow中显示吗?
Yes.
If it does have to be in an NSWindow, how do I stop the window from drawing a title bar and other chrome?
如果它必须在NSWindow中,如何阻止窗口绘制标题栏和其他chrome?
Use NSBorderlessWindowMask when you create your window. (Assuming you aren't using a custom subclass of NSWindow, this means not creating the window instance in a nib. If you want to lay out your view hierarchy in a nib, do that in a top-level custom view, then load the nib and set that view as the window's content view.)
创建窗口时使用NSBorderlessWindowMask。 (假设您没有使用NSWindow的自定义子类,这意味着不在nib中创建窗口实例。如果要在nib中布置视图层次结构,请在*自定义视图中执行此操作,然后加载nib并将该视图设置为窗口的内容视图。)