带有“标题栏”的 NSPanel在 Interface Builder 中取消选中不会出现
所以我以为我已经完成了我的基础,但显然我错过了一两个关键步骤。
我有一个 NSPanel,当按下 NSStatusItem 时会显示 (makeKeyAndOrderFront:
)。一切都很好,但是当 NSPanel 显示标题栏时,面板也是可拖动的。 (这是不希望的。)
第一个屏幕截图显示了在 Interface Builder 的“外观”类别中启用“标题栏”的面板。 (抱歉,内容有些模糊,目前一切仍处于锁定状态。)
唯一
我尝试过的事情:
我已经对 NSPanel 进行了子类化经过一番研究后,为
canBecomeKeyWindow
和canBecomeMainWindow
返回了YES
,但是(在子类化之前)这些方法都返回了NO
无论我是否使用标题栏。所以我不认为这是问题所在。我已确保 NSPanel 的框架已正确设置。它具有良好的高度,并且原点也设置正确。
编辑:忘记提及:
该应用程序是一个仅包含菜单栏的应用程序。在下面的屏幕截图中,请注意,在 Info.plist
中添加了一个附加条目来强制执行此操作。
So I thought I had covered my bases, but apparently I'm missing a key step or two.
I have an NSPanel that is displayed (makeKeyAndOrderFront:
) when an NSStatusItem is pressed. Things work great, but as the NSPanel displays a title bar, the panel is also draggable. (This is undesired.)
The first screenshot shows the panel with "Title Bar" enabled in Interface Builder, in the Appearance category. (Sorry for the blur, things are still under lock and key for now.)
The only change that is made in Interface Builder is unchecking the "Title Bar" checkbox. I then save and re-run, and that's what you see in the second screenshot. While a slight shadow appears, the panel does not.
Things I've tried:
I've subclassed the NSPanel and returned
YES
forcanBecomeKeyWindow
andcanBecomeMainWindow
after a bit of research, but (prior to subclassing) these methods both returnedNO
regardless of whether I was using a Title Bar or not. So I don't think this is the issue.I've ensured that the frame for the NSPanel is properly set. It has a good height, and the origin is set properly as well.
Edit: Forgot to Mention:
The application is a menu-bar-only application. In the screenshot below, note that an additional entry was added to Info.plist
to enforce this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我过去曾遇到过这个问题。我首先“忽略”其他应用程序,然后将其设为关键窗口,从而解决了这个问题。尝试一下,看看它是否适合您。
另外,请尝试在初始化期间将窗口级别设置为
NSPopUpMenuWindowLevel
。我在 Mac OS X 上加载 nib 文件的方式也遇到了问题。它们是“延迟”加载的,这意味着它们在需要时不会被初始化。当您想要在窗口上设置细节时,这会导致问题,但您却不能这样做,因为由于延迟笔尖加载,似乎没有调用
awakeFromNib
。为了解决这个问题,这是我过去所做的。在您的委托中(或初始化窗口的任何位置),通过访问初始化类上的window
属性来启动窗口:通过这样做,您将强制笔尖初始化。这样,当用户单击菜单栏图标时,笔尖已经初始化,并且
awakeFromNib
已经被调用。I've had problems with this in the past. I was able to resolve it by first "ignoring" other apps, then making it the key window. Give it a shot and see if it works for you.
Also, try setting the window level to
NSPopUpMenuWindowLevel
during initialization.I have also had problems with the way that nib files are loaded on Mac OS X. They're loaded "lazily", which means that they won't be initialized until they're needed. This causes a problem when you're wanting to set specifics on the window, but you can't because
awakeFromNib
doesn't seem to be called, due to lazy nib loading. To fix this, here's what I've done in the past. In your delegate (or wherever you initialize your window), kick the window into action by accessing thewindow
property on the initialized class:By doing so, you're forcing the nib to initialize. That way, when the user clicks the menubar icon the nib is already initialized, and
awakeFromNib
has already been called.您是说 makeKeyAndOrderFront: 在这个 NSPanel 对象上运行您的应用程序时不显示它吗?我刚刚创建了一个示例项目,NSButton 触发相同类型的 NSPanel 来显示,并且它工作正常.. titleBar 是否启用。
http://cl.ly/3d0U3C0P3u2D0m3T1w1N
Are you saying makeKeyAndOrderFront: on this NSPanel object doesn't display it when running your app? I just created a sample project, NSButton triggers the same type of NSPanel to display, and it works fine.. titleBar enabled or not.
http://cl.ly/3d0U3C0P3u2D0m3T1w1N