[英]How to implement my own pop-up control in Cocoa?
I want to make a custom autocomplete control for my NSWindow, sort of like Xcode's fancy one, but I can't quite figure out how. 我想为我的NSWindow做一个自定义的自动完成控件,有点像Xcode的花哨的控件,但是我不知道怎么做。
I made an NSPanel with its own NSWindowController, and I display it with some code like: 我用自己的NSWindowController制作了一个NSPanel,并用一些代码来显示它:
_popupController = [[MYPopupWindowController alloc] initWithWindowNibName: @"MYPopupPanel"];
NSPanel *popup = [_popupController window];
[popup setFrameTopLeftPoint: ...]; // location of the cursor
[popup setLevel: NSPopUpMenuWindowLevel];
[_window addChildWindow: popup ordered: NSWindowAbove];
[_popupController showWindow: sender];
The NSPanel itself has its own subclass which implements -canBecomeKeyWindow
(returning YES), so that the NSTableView in the popup can receive key events. NSPanel本身具有实现
-canBecomeKeyWindow
(返回YES)的子类,因此弹出窗口中的NSTableView可以接收键事件。
This works pretty well. 效果很好。 The only problem I have with this is that when my NSPanel is the key window, the main app NSWindow is not (obviously), which causes the red/yellow/green window controls to go dim.
我唯一遇到的问题是,当我的NSPanel是关键窗口时,主应用程序NSWindow没有(很明显)没有,这导致红色/黄色/绿色窗口控件变暗。 Clearly, in programs like Xcode, the window controls don't dim every time you start to type a method name.
显然,在Xcode之类的程序中,每次您开始输入方法名称时,窗口控件都不会变暗。
Am I barking up the wrong tree? 我在树上叫错了吗? Is NSPanel the wrong way to make a custom pop-up control?
NSPanel是制作自定义弹出控件的错误方法吗? Or is there some way to make an NSPanel become the key window without its parent window (or other windows) dimming their window controls?
还是有某种方法可以使NSPanel成为关键窗口,而其父窗口(或其他窗口)不会使其窗口控件变暗?
EDIT: Is there any way to find out what Xcode is actually using, like whether it's an NSPanel? 编辑:有没有办法找出实际使用的Xcode,例如它是否是NSPanel?
尝试将NSNonactivatingPanelMask
标志添加到您的NSPanel
样式中(如果使用xib,只需在“属性”检查器中设置“非激活”复选框)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.