可可屏幕保护程序配置面板自由浮动
我正在使用 Cocoa 的 ScreenSaver API 编写一个屏幕保护程序。它是为 64 位架构编译的,我在 Lion 上运行它。
为了启用配置,我在主视图中添加了以下内容:
- (BOOL)hasConfigureSheet
{
return YES;
}
- (NSWindow*)configureSheet
{
if (configureSheet == nil) {
if (![NSBundle loadNibNamed: @"WTConfigureSheet" owner: self]) {
NSLog(@"Failed to load config sheet");
return nil;
}
}
ScreenSaverDefaults *defaults =
[ScreenSaverDefaults defaultsForModuleWithName: WTModuleName];
backgroundColorWell.color = [defaults objectForKey: @"BackgroundColor"];
lightLetterColorWell.color = [defaults objectForKey: @"LightLetterColor"];
darkLetterColorWell.color = [defaults objectForKey: @"DarkLetterColor"];
return configureSheet;
}
全新安装保护程序后,单击“选项”使配置表不再显示为工作表,而是自由浮动在屏幕上,没有边框。否则,它会正常工作并在被解雇后消失。
当我第二次单击“选项”时,配置表再次出现,这次正确地作为首选项窗口的表。然后它立即冻结,因此我无法单击它的任何控件。
有谁知道是什么原因导致这种行为?
I'm writing a screen saver using Cocoa's ScreenSaver API. It's compiled for 64-bit arch and I'm running it on Lion.
In order to enable configuration, I have added the following to the main view:
- (BOOL)hasConfigureSheet
{
return YES;
}
- (NSWindow*)configureSheet
{
if (configureSheet == nil) {
if (![NSBundle loadNibNamed: @"WTConfigureSheet" owner: self]) {
NSLog(@"Failed to load config sheet");
return nil;
}
}
ScreenSaverDefaults *defaults =
[ScreenSaverDefaults defaultsForModuleWithName: WTModuleName];
backgroundColorWell.color = [defaults objectForKey: @"BackgroundColor"];
lightLetterColorWell.color = [defaults objectForKey: @"LightLetterColor"];
darkLetterColorWell.color = [defaults objectForKey: @"DarkLetterColor"];
return configureSheet;
}
After installing the saver freshly, clicking "Options" makes the config sheet appear not as a sheet, but floating freely on the screen, without a border. Otherwise, it works correctly and disappears after being dismissed.
When I click "Options" a second time, the config sheet appears again, this time correctly as a sheet of the preferences window. It then immediately freezes, so that I can't click any of its controls.
Does anyone have an idea what causes this behavior?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我今天遇到了和你一样的问题,我花了相当长的时间才解决这个问题,所以这是我的解决方案:
我发现只要你调用
loadNibNamed:owner 就会出现
。因此必须有某种机制可以从笔尖自动打开窗口。NSWindow
:因此,我重新检查了笔尖,发现属性检查器窗格中有一个名为“Visible At Launch”的选项,默认情况下会选中该选项。
解决方案非常简单:只需取消选中该复选框即可按预期工作。
我发现它很容易被忽视,因为您期望窗口打开,但它实际上打开两次(一次自动打开,第二次因为 System Preferences.app 将其显示为表格),这会导致故障。
可能发生的另一个问题是,在第一次关闭并重新打开窗口后,它会冻结,具体取决于您在类上定义 ivar / 属性的方式。
这是因为默认情况下窗口在关闭时会自行释放。
因此,请务必在界面生成器中取消选中“关闭时释放”。
I had the same problem as you today and it took me quite some time to figure this one out, so here's my solution:
I discovered that the
NSWindow
appears as soon as you callloadNibNamed:owner:
. So there had to be some sort of mechanism to automatically open windows from nibs.So I re-checked the nib and saw that there is an option called
"Visible At Launch"
on the attribute inspector pane which is checked by default.The solution is very simple: just uncheck that checkbox and it works as expected.
I find it easy to overlook since you expect the window to open, but it actually opens twice (once automatically and a second time because System Preferences.app shows it as a sheet) which leads to the glitches.
Another problem that could happen, depending on how you defined the ivar / property on your class is that after the first close and re-open of the window it just freezes.
This is because per default the window releases itself when closed.
So be sure to also uncheck
"Release When Closed"
in interface builder.为了使此代码按编写的方式工作,您需要在主视图的头文件中创建一个名为
configureSheet
的NSWindow*
类型的 IBOutlet,保存该文件,以便 Interface Builder 可以看到更改,然后在 Interface Builder 中加载 WTConfigureSheet.xib 并将顶层窗口组件连接到 Files Owner ->配置表。For this code to work as written, you need to create an IBOutlet of type
NSWindow*
namedconfigureSheet
in your main view's header file, save that file so Interface Builder can see the change, then load WTConfigureSheet.xib in Interface Builder and connect up the toplevel window component to Files Owner -> configureSheet.