Subclassing an NSDrawer's contentView to implement a completely custom drawer

前端 未结 2 1196
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 05:13

I want to implement my own custom drawer completely by subclassing NSView and doing all my view drawing in that. I\'ve created a custom NSView class that does hardly anythin

相关标签:
2条回答
  • 2021-01-15 05:27

    I made a custom drawer by subclassing NSWindow rather than NSDrawer. It was a lot of work. There is a private object, NSThemeFrame, that sits between a NSWindow and its contentView. To avoid using private API, you have to make a transparent window and let its contentView act like a NSThemeFrame. Matt Gallagher shows how: http://cocoawithlove.com/2008/12/drawing-custom-window-on-mac-os-x.html

    0 讨论(0)
  • 2021-01-15 05:51

    That frame is being drawn by the drawer's frame view. To do this, you need to use some private methods, and the easiest way is probably to use a custom subclass of NSDrawer. I do not know the specific methods used for drawers, but you can get a header for the class including private methods using class-dump.

    Edit: This is what NSDrawer actually does.

    NSDrawer is an opaque object that manages other objects. It creates a window using the private NSDrawerWindow class. Setting its content view sets the window's content view. The NSDrawerWindow class uses the private NSDrawerFrame class, which is a subclass of the private NSFrameView class, as its background and displays its content view inside that.

    To change the frame, you need a way to change the frame view in the window. The easiest thing to do would be to get a header for NSDrawerWindow and add a category that overrides +frameViewClassForStyleMask: to return the class for your custom view. Your custom view should be a subclass of NSFrameView, which means you also need a header for that class.

    0 讨论(0)
提交回复
热议问题