[英]How can I make a custom NSWindow subclass into a custom NSPanel?
I'm using a very complex custom subclass of NSWindow called MyWindow
. 我正在使用NSWindow的非常复杂的自定义子类MyWindow
。 Now I want to make a new class called MyPanel
which has the same behavior as NSPanel, but which inherits from MyWindow
as it's superclass. 现在,我想创建一个名为MyPanel
的新类,该类具有与NSPanel相同的行为,但是它继承自MyWindow
是其超类。 I've read the official docs for NSPanel
but it doesn't say how to make a panel from custom NSWindow subclasses. 我已经阅读了NSPanel
的官方文档 ,但没有说如何从自定义NSWindow子类制作面板。 My current code: 我当前的代码:
MyPanel.h MyPanel.h
#import "MyWindow.h"
@interface MyPanel : MyWindow
- (BOOL)isFloatingPanel;
- (void)setFloatingPanel:(BOOL)flag;
- (BOOL)becomesKeyOnlyIfNeeded;
- (void)setBecomesKeyOnlyIfNeeded:(BOOL)flag;
- (BOOL)worksWhenModal;
- (void)setWorksWhenModal:(BOOL)flag;
@end
MyPanel.m MyPanel.m
#import "MyPanel.h"
@implementation MyPanel
@end
So now how can I accomplish this without directly subclassing NSPanel
(which would mean I'd have to copy and paste all the code from MyWindow
to MyPanel
)? 因此,现在如何在不直接子类化NSPanel
情况下实现这NSPanel
(这意味着我必须将所有代码从MyWindow
复制并粘贴到MyPanel
)? What methods, delegates, properties do I have to recreate/implement to get the same behavior as an NSPanel? 我必须重新创建/实现哪些方法,委托,属性才能获得与NSPanel相同的行为?
It sounds like you already answered the question yourself. 听起来您已经亲自回答了这个问题。 NSPanel is a subclass of NSWindow, so instead of subclassing NSWindow you should subclass NSPanel. NSPanel是NSWindow的子类,因此您应该将NSPanel子类化,而不是将NSWindow子类化。 That being said.. If you're careful you can create an NSPanel and change its superclass programmatically to an instance of MyWindow. 话虽如此..如果您小心的话,可以创建一个NSPanel并以编程方式将其超类更改为MyWindow的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.