简体   繁体   English

Mac OSX App下拉菜单

[英]Mac OSX App Drop Down menu

How do I create a drop down menu that I can add as a subview to an NSView in an OSX app? 如何创建一个可以作为子视图添加到OSX应用程序中的NSView的下拉菜单? I've been looking online and can't really find any information on the subject. 我一直在网上寻找,实际上找不到关于该主题的任何信息。

This Apple document demonstrates how to create a menu on mouse down : Apple文档演示了如何在鼠标按下时创建菜单:

- (void)mouseDown:(NSEvent *)theEvent {
    NSMenu *theMenu = [[NSMenu alloc] initWithTitle:@"Contextual Menu"];
    [theMenu insertItemWithTitle:@"Beep" action:@selector(beep:) keyEquivalent:@"" atIndex:0];
    [theMenu insertItemWithTitle:@"Honk" action:@selector(honk:) keyEquivalent:@"" atIndex:1];
    [NSMenu popUpContextMenu:theMenu withEvent:theEvent forView:self];
}

but there are other ways of doing it as well, but it depends exactly how and when you want the menu displayed. 但是也可以通过其他方式来实现,但这完全取决于您希望菜单显示的方式和时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM