我有一个像这样的标准 NSMenu
此菜单是使用以下代码创建的:
NSMenu *menu = [[NSMenu alloc] init];
NSMenuItem *addMenuItem = [[NSMenuItem alloc] init];
[addMenuItem setTitle:[NSString stringWithFormat:@"Upload"]];
[addMenuItem setHidden:NO];
[addMenuItem setRepresentedObject:contentType];
[addMenuItem setTarget:self];
[addMenuItem setAction:@selector(performSelectedDragOperation:)];
[addMenuItem setTag:operation];
[addMenuItem setEnabled:YES];
[menu addItem:addMenuItem];
NSMenuItem *alterMenuItem = [addMenuItem copy];
[alterMenuItem setTitle:@"Upload in Folder"];
[alterMenuItem setKeyEquivalentModifierMask:NSAlternateKeyMask];
[alterMenuItem setAlternate:YES];
[menu addItem:alterMenuItem];
[alterMenuItem release];
[addMenuItem release];
NSMenuItem *addMenuItem2 = [[NSMenuItem alloc] init];
[addMenuItem2 setTitle:[NSString stringWithFormat:@"EditNewAndUpload"]];
[addMenuItem2 setHidden:NO];
[addMenuItem2 setRepresentedObject:contentType];
[addMenuItem2 setTarget:self];
[addMenuItem2 setAction:@selector(performSelectedDragOperation:)];
[addMenuItem2 setTag:operation];
[addMenuItem2 setEnabled:YES];
[menu addItem:addMenuItem2];
NSMenuItem *alterMenuItem2 = [addMenuItem2 copy];
[alterMenuItem2 setTitle:@"EditNewAndUpload in Folder"];
[alterMenuItem2 setKeyEquivalentModifierMask:NSAlternateKeyMask];
[alterMenuItem2 setAlternate:YES];
[menu addItem:alterMenuItem2];
[alterMenuItem2 release];
[addMenuItem2 release];
如您所见,菜单中的每个选项都有一个“重复”项。option当您在菜单可见时按下 (alt) 键时,将显示该项目的副本。
问题是菜单大小在显示备用菜单项时会发生变化,因为此菜单的标题大于原始菜单,并且它永远不会恢复为原始大小,从而产生以下结果:
知道如何解决吗?谢谢