3

我有一个像这样的标准 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) 键时,将显示该项目的副本。

问题是菜单大小在显示备用菜单项时会发生变化,因为此菜单的标题大于原始菜单,并且它永远不会恢复为原始大小,从而产生以下结果:

在此处输入图像描述

知道如何解决吗?谢谢

4

2 回答 2

3

这是正常行为,您不必担心。如果你想改变它,提交一个 bug

于 2011-07-09T01:21:48.657 回答
0

您只需要更改 NSMenuItem 标题

[[appmenu itemAtIndex:0]setTitle:[NSString stringWithFormat:@"EditNewAndUpload \t \t \t \t \t"]];
于 2015-08-06T13:27:38.710 回答