我创建了NSApplication子类:
class MyApplication: NSApplication {
override func sendEvent(theEvent: NSEvent) {
if theEvent.type == NSEventType.KeyUp && (theEvent.modifierFlags & .CommandKeyMask).rawValue != 0 {
self.keyWindow?.sendEvent(theEvent)
} else {
super.sendEvent(theEvent)
}
}
}
Run Code Online (Sandbox Code Playgroud)
之后,我将Info.plist中的"Principal class"更改为MyApplication,最后在Main.storyboard的Application Scene中,我也将Application更改为MyApplication.
当我运行应用程序时,我得到以下消息:
class MyApplication: NSApplication {
override func sendEvent(theEvent: NSEvent) {
if theEvent.type == NSEventType.KeyUp && (theEvent.modifierFlags & .CommandKeyMask).rawValue != 0 {
self.keyWindow?.sendEvent(theEvent)
} else {
super.sendEvent(theEvent)
}
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我弄这个吗?
在我的cocoa应用程序中,我使用以下命令将NSPanel显示为另一个NSPanel的模态"窗口":
[modalPanel setWorksWhenModal:YES];
[[NSApplication sharedApplication] beginSheet:modalPanel modalForWindow:mainPanel modalDelegate:nil didEndSelector:nil contextInfo:nil];
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是在该模态"窗口"中显示的NSTextField不允许复制和粘贴.
从搜索我发现Cocoabuilder上的以下线程看起来几乎是同样的问题,但是在该线程中也没有给出解决方案.
http://www.cocoabuilder.com/archive/message/cocoa/2007/11/6/192462
该线程说要确保您没有通过使用验证来停止复制/粘贴,但对我来说情况并非如此,因为我目前没有对任何字段进行任何验证.
有什么特别的东西我必须要做到这一点,或者有没有人对我可以检查/尝试的任何想法?
谢谢!
在Mac OS X中,我需要调用什么API才能在整个屏幕上放置一个窗口,而不仅仅是菜单栏和底座?此外,是否可以有效地"锁定"屏幕到这个位置,禁用任务控制,启动板等?
我在App Delegate的实现文件中尝试了以下代码:
- (void)awakeFromNib {
@try {
NSApplicationPresentationOptions options = NSApplicationPresentationDisableForceQuit + NSApplicationPresentationDisableHideApplication + NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideDock + NSApplicationPresentationHideMenuBar + NSApplicationPresentationFullScreen;
[NSApp setPresentationOptions:options];
NSLog(@"Set presentation options");
}
@catch (NSException *exception) {
NSLog(@"Error. Invalid options");
}
}
Run Code Online (Sandbox Code Playgroud)
NSLog读取"设置演示选项",但没有其他任何事情发生.有小费吗?