作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Cocoa 编写一个多文档应用程序。用户打开文档时必须输入密码。在一段时间内没有对文档进行任何操作后,用户将再次被要求输入密码。
现在,我正在使用 NSAplication
的 beginSheet:modalForWindow:modalDelegate:didEndSelector:contextInfo:
在自定义工作表中显示密码提示。虽然它有效,但它有一个不幸的副作用,即即使当时正在处理另一个文档,窗口也会被带到前面并获得焦点。只有当我的应用程序位于前面时才会出现问题。
如果父窗口未处于事件状态,是否有办法防止打开的工作表夺取焦点?
最佳答案
没有简单的方法。黑客的方法是为文档的窗口和工作表的窗口创建 NSWindow 的子类,并在该类中重写 orderFront: 和 makeKeyWindow,以便在调用 beginSheet 期间不执行任何操作。例如,
在 NSWindow 子类中:
-(void)awakeFromNib
{
hack = NO;
}
-(void)hackOnHackOff:(BOOL)foo
{
hack = foo;
}
- (void)orderFront:(id)sender
{
if (!hack)
[super orderFront:sender];
}
- (void)makeKeyWindow
{
if (!hack)
[super makeKeyWindow];
}
然后你的 beginSheet 调用将如下所示:
-(void)sheet
{
SpecialSheetWindow* documentWindow = [self windowForSheet];
[documentWindow hackOnHackOff:YES];
[sheetWindow hackOnHackOff:YES];
[[NSApplication sharedApplication] beginSheet:sheetWindow
modalForWindow:documentWindow
modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil];
[documentWindow hackOnHackOff:NO];
[sheetWindow hackOnHackOff:NO];
}
关于objective-c - 防止自定义工作表抢夺焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10678592/
我刚开始在 Ubuntu 14.04.4 系统上编写一些 (C++) 代码以通过 DVB 电视 USB 调谐器访问 DVB 流。我正在使用 libdvbv5。我在英国使用地面免费观看。 正在尝试获取停
我是一名优秀的程序员,十分优秀!