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

前端 未结 2 1203
隐瞒了意图╮
隐瞒了意图╮ 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: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.

提交回复
热议问题