【问题标题】:How to disable all drag-and-drop operations when NSAlert is shown as modal window当 NSAlert 显示为模式窗口时如何禁用所有拖放操作
【发布时间】:2016-04-25 14:21:44
【问题描述】:

我有带有自定义 NSView 的 NSWindow。这个自定义的 NSView 覆盖 performDragOperation 方法。拖放操作效果很好。但是当我创建 NSAlert 并将其显示为模态窗口时,我需要块拖放,不应该调用方法 performDragOperation。

NSAlert *alert = [[NSAlert alloc]init];
[alert addButtonWithTitle:@"Excellent"];
[alert setMessageText:@"This is your message."];
[alert runModal];

一种可能的解决方案是添加代码来验证对话框是否显示为 performDragOperation 方法。但是如何检测是否显示了 NSAlert。 例如我可以使用的工作表:

if([window attachedSheet]) {
   ...
}

但是如何做到这一点

[alert runModal];

【问题讨论】:

  • NSApplication 有一个属性modalWindow
  • 谢谢威勒克。这正是我所需要的。

标签: objective-c cocoa drag-and-drop nsalert


【解决方案1】:

根据 Willeke cmets,可以使用下一个代码来检测是否有一些 Alert 正在运行:

if([NSApp modalWindow]) { 
  ...
}

【讨论】:

    猜你喜欢
    • 2017-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多