问题标签 [nswindow]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1355 浏览

objective-c - Layering Cocoa WebView - Drawing on top?

webview in core animation layer

The only other thread I can find is the above which doesn't necessarily fit my needs. Is there a reliable way to simply draw a view on top of a webview? I've tried to layer a regular NSView on top of WebView, and it draws right at first, but any movement in the webview (scrolling the page etc) appears to invalidate the view and produces visual artifacts.

I've tried:

No luck there, same problems -- z-ordering doesn't seem to work unless I'm missing something.

Is this just a limitation of webviews?

I also tried implementing the view above as a window, which worked much better (just controlled the location of the window programmatically). However, the desired behavior is for the user to enter some text into this window, but for it not to steal "focus" -- ie the main window goes inactive (the x - + go gray) when the user clicks on the text field in the new window. Any way to avoid that?

I've tried subclassing NSWindow and overriding canBecomeKey (return YES) and canBecomeMain (return NO) but the window still steals focus.

EDIT: I weep :-( I can't figure out a way around the drawing over webkit thing. I did, on the other hand, figure out a way to force the main window of my app to retain active state even though you have a popup window with key state. However, it has unintended consequences when using the text input on the popup dialog (which has to be forced into the key window state). Backspace doesn't work :: shakes head ::, and mouse events are not getting distributed to the webkit views below (for mouseovers on components embedded in the html). Craptacular.

Josh

0 投票
2 回答
1087 浏览

objective-c - Cocoa NSWindow 不更新数据

我有一个 NSWindow,当您单击两个项目中的任何一个(都来自 NSTableView)时,它会显示出来。我有一个 setter 方法,它告诉窗口要显示什么信息。这一切都很完美,直到需要在窗口中显示数据。如果我使窗口从一个表视图显示,然后尝试让它显示另一个它不这样做的新数据,它会保留旧数据。

我使用完全相同的方法从两种可能的方式获取和显示数据,以显示窗口,并且数据正在正确更改。显示我正在使用的窗口[mywindow makeKeyAndOrderFront:self];

并且一个表视图与窗口属于同一类,而另一个则不是

0 投票
2 回答
3691 浏览

cocoa - Snow Leopard & LSUIElement -> 应用程序未正确激活,窗口未“激活”,尽管是“键”

我在后台应用程序中遇到了一些问题,该应用程序使用 LSUIElement=1 隐藏其停靠项、菜单栏并防止它出现在 Command-Tab 应用程序切换器中。

这似乎是雪豹唯一的问题。

应用程序在菜单栏中放置一个 NSStatusItem 并在单击时弹出一个菜单。选择“首选项...”应该会弹出一个带有首选项的 NSWindow。

似乎不起作用的第一件事是窗口没有在前面排序,而是出现在所有其他应用程序窗口的后面。

我试图通过调用来解决这个问题

但这没有用。

过了一会儿,我发现菜单阻止了向运行循环发送消息,所以我在 MainController 上编写了另一个方法并延迟发送消息:

[self performSelector:@selector(setFront:) withObject: [preferencesController window] afterDelay:1.0];

请注意发送每一个可能的消息以使它做它应该做的方法。

这工作,有点,窗口被带到所有应用程序的所有其他窗口顶部的前面,但大多数时候它是不活动的,这意味着它的标题栏是灰色的。单击标题栏也不会使窗口处于活动状态。单击窗口的内部将使其处于活动状态!?

在 Leopard 中,这一切似乎都不是问题。只需调用 activateIgnoringOtherApps 并使窗口键似乎工作得很好。

在 Snow Leopard 中,有一个新的 API 旨在替换 LSUIElement 以模拟其行为:

http://developer.apple.com/mac/library/releasenotes/cocoa/appkit.html

我已经玩过了,但它只是 SL,我无法设置 LSUIElement。

0 投票
2 回答
2338 浏览

cocoa - Cocoa/Objective-C - 带有文本输入的子窗口,而主窗口没有变为非活动状态

我需要在可可应用程序中生成一个悬停在我的主窗口上方的窗口。我希望这个主窗口允许用户在输入框中输入一些文本。一切都很好,直到文本输入框真正获得焦点。主窗口变为“停用”。这个窗口是无边界的,并且是一个稍微自定义的形状——我想它更像是一个悬停卡而不是其他任何东西。

基本上,我希望这个东西几乎可以像 Spotlight (Apple + Space) 一样工作——你可以输入文本,但这是一个辅助操作,在更大的 UX 的背景下,你不想要不和谐主窗口变灰(变为非活动状态)的效果。您会注意到,当您打开某个应用程序并处于焦点位置时,聚光灯不会导致该应用程序的窗口变为非活动状态。

出现这个问题是因为文本输入似乎需要子窗口成为关键窗口(它不会让您将光标放在文本输入字段中)。当它成为键时,主窗口变为非活动状态。

到目前为止,我已经尝试过:

  • 为我的主应用程序子类化 NSWindow 并覆盖isKeyWindow,这样它只会在应用程序不再是用户焦点(而不是窗口)时丢失密钥。这产生了与子窗口的键状态发生冲突并对键盘输入产生非常奇怪的影响(某些键未捕获,如删除)的意外影响
  • 创建视图而不是窗口。由于这个问题,它不起作用——这些天你不能在 Webkit WebView 上绘图。

任何 Cocoa/OSX 向导有什么想法吗?我对这个有点着迷了。痒痒的,抓不住。

编辑:还尝试在子窗口上覆盖以下内容。单击时,该窗口会使主应用程序窗口变为非活动状态。

编辑 2:在使用 NSMenu 一段时间后,我放弃了这种方法。然而,我似乎发现了一些东西。在 NSPanel 中有一个名为的窗口样式掩码:

现在试试这个...

编辑 3: NSNonactivatingPanelMask 没有做到这一点。没有想法。

0 投票
1 回答
1872 浏览

objective-c - 可可中的下拉视图

我正在寻找一个位于主窗口前面的“下拉”视图。这方面的一个例子是当您在系统偏好设置->网络中单击“高级”时下拉的窗口。

如果有人能在文档方面指出我正确的方向,那就太好了。提前致谢。

0 投票
3 回答
9769 浏览

cocoa - 更改 NSWindow 标题栏的颜色

我正在开发一个桌面应用程序,我想在其中更改 NSWindow 标题栏的颜色。我该怎么做?

0 投票
2 回答
7136 浏览

cocoa - Detecting if the window is a key window in cocoa

I am making a application that the user will have to interact with one window and when they have that window configured the way they want it they switch to a different application then my application will begin to do other stuff which i will have defined in a method

say for an example program when the main window has focus it contains a label that says "i am focused" and when the person clicks on the desktop or another window/application then the label will read "i am not focused".

Thanks

0 投票
1 回答
957 浏览

cocoa - 尝试关闭时 NSWindow 显示警报

当 NSWindow 尝试关闭时,如何显示 NSAlert?这也必须打开和关闭。

0 投票
1 回答
223 浏览

cocoa - 在 nswindow 上动态删除和附加边框

创建后如何添加/删除窗口边框?窗口已经在界面生成器中设计,我宁愿避免纯粹用代码编写窗口,因为我还有很长的路要走才能说我对 Objective-c/cocoa 有经验。

示例程序:
最初带有边框的单个窗口,上面有一个按钮。如果您单击该按钮,一旦它使边界消失,如果您再次单击它,则边界重新出现。

谢谢

0 投票
1 回答
1789 浏览

cocoa - NSWindow 不显示

我在不使用 Interface Builder 的情况下尝试显示 NSWindow 时遇到问题。窗口的初始化非常混乱,因为我更熟悉 iPhone(它没有等效的 NSWindow)。所以我在谷歌上搜索了一些代码,我最终发现了这个:

所以我复制了该代码并将其放入applicationDidFinishLaunching并认为一切都会好起来的。但一切都不好。Xcode 没有在构建结果中显示任何错误(或警告)。但是,我确实在显示日志中收到了这条消息:

我不知道如何解释这一点,因为谷歌在搜索此显示日志错误的解决方案时失败了。而且,据我所知,我目前没有任何行动,包括一项行动buttonPressed。附带说明:我不知道这是否相关,但我在 info.plist 中删除了 Main Window.xib 及其随附属性。

任何帮助将不胜感激。

更新:我尝试做一些printf调试(从来没有真正打扰过学习NSLog),即使printf事情是在最开始appliactionDidFinishLaunching甚至最糟糕的开始时main(如果你们中的一些人想在返回之前),事情也不会问我是把 printf 放在return语句之前还是之后)。