xcode 内联菜单不显示在ventura mac催化剂

eiee3dmh  于 2023-03-31  发布在  Mac
关注(0)|答案(1)|浏览(171)

我的Mac Catalyst应用程序构建在Monterey 12.6.3上,Xcode 14.2最低macOS Catalina 11.2。主菜单在Main.storyboard中定义,并具有自定义的文件菜单,其中包含3个内联部分。当应用程序在Catalina或Monterey中运行时,文件菜单如下所示:

但是当应用程序在Ventura上运行时,文件菜单看起来像这样:

我所有的内联菜单项在Ventura中都丢失了,我没有发现故事板中主菜单的任何修改,这将使丢失的项目出现在Ventura中。故事板中的主菜单看起来像这样:

我的问题是:* 如何修改主菜单的情节串联图板定义,使Monterey和Ventura中的菜单相同?*
我相信可以使用App Delegate overridebuildMenuWithBuilder函数构建我的菜单,但我想知道为什么故事板定义不再适用于macOS Catalina 到Ventura!

mdfafbf1

mdfafbf11#

由于我无法得到这个问题的答案,我决定使用App Delegate重写buildMenuWithBuilder()来重建菜单:

#if TARGET_OS_UIKITFORMAC
// Fix Issue #009 - Unusable File menu on Ventura                               //leg20230209 - MultiNotes_Catalyst_v1
//  Build File Menu from code instead of using storyboard.
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
{
    [super buildMenuWithBuilder: builder];
    
    // Remove unwanted menus.
    [builder removeMenuForIdentifier:UIMenuServices];
    [builder removeMenuForIdentifier:UIMenuFormat];
    [builder removeMenuForIdentifier:UIMenuClose];
    [builder removeMenuForIdentifier:UIMenuPrint];
    [builder removeMenuForIdentifier:UIMenuFind];

    // NOOP this call when compiling on Catalina and Xcode 12.4 because
    //  macCatalyst 16.0 SDK not available.
#if BUILDING_ON_MONTEREY
    if (@available(macCatalyst 16.0, *)) {
        [builder removeMenuForIdentifier:UIMenuDocument];
    }
#endif
    
    // Build inline "New" menu section.
    UIKeyCommand* newNoteCommand = [UIKeyCommand keyCommandWithInput:@"N" modifierFlags:UIKeyModifierCommand action:@selector(newNoteMenuCMD:)];
    newNoteCommand.title = @"New Note";
    newNoteCommand.discoverabilityTitle = @"Create a new Note in selected Group";

    UIKeyCommand* newGroupCommand = [UIKeyCommand keyCommandWithInput:@"G" modifierFlags:UIKeyModifierCommand+UIKeyModifierShift action:@selector(newGroup)];
    newGroupCommand.title = @"New Group";
    newGroupCommand.discoverabilityTitle = @"Create a new Group in selected Group";

    UIKeyCommand* deleteNoteOrGroupCommand = [UIKeyCommand keyCommandWithInput:@"\b" modifierFlags:UIKeyModifierCommand action:@selector(deleteNoteOrGroup:)];
    deleteNoteOrGroupCommand.title = @"Delete Note or Group";
    deleteNoteOrGroupCommand.discoverabilityTitle = @"Delete selected Note or Group";

    UIKeyCommand* duplicateNoteCommand = [UIKeyCommand keyCommandWithInput:@"R" modifierFlags:UIKeyModifierCommand action:@selector(duplicateNote:)];
    duplicateNoteCommand.title = @"Duplicate Note";
    duplicateNoteCommand.discoverabilityTitle = @"Duplicate selected Note";

    UIMenu* newMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.newmenu" options: UIMenuOptionsDisplayInline children: @[newNoteCommand, newGroupCommand, deleteNoteOrGroupCommand, duplicateNoteCommand]];
    [builder insertChildMenu: newMenu atStartOfMenuForIdentifier: UIMenuFile];

    
    // Build inline "Import" menu section.
    UIKeyCommand* importNotesCommand = [UIKeyCommand keyCommandWithInput:@"" modifierFlags:0 action:@selector(importNotes:)];
    importNotesCommand.title = @"Import Notes…";
    importNotesCommand.discoverabilityTitle = @"Import selected .txt, .html, and .rtf note files from selected folder";     //leg20230220 - MultiNotes_Catalyst_v1

    UIKeyCommand* exportNoteAsHTMLCommand = [UIKeyCommand keyCommandWithInput:@"E" modifierFlags:UIKeyModifierCommand action:@selector(exportNoteAsHTML:)];
    exportNoteAsHTMLCommand.title = @"Export Note As HTML…";
    exportNoteAsHTMLCommand.discoverabilityTitle = @"Export Note as an HTML file";

    UIKeyCommand* exportNoteAsRTFCommand = [UIKeyCommand keyCommandWithInput:@"E" modifierFlags:UIKeyModifierCommand+UIKeyModifierShift action:@selector(exportNoteAsRTF:)];
    exportNoteAsRTFCommand.title = @"Export Note As RTF…";
    exportNoteAsRTFCommand.discoverabilityTitle = @"Export Note as an RTF file";

    UIMenu* importMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.importmenu" options: UIMenuOptionsDisplayInline children: @[importNotesCommand, exportNoteAsHTMLCommand, exportNoteAsRTFCommand]];
    [builder insertChildMenu: importMenu atEndOfMenuForIdentifier: UIMenuFile ];

    
    // Build inline "Print" menu section.
    UIKeyCommand* printNoteCommand = [UIKeyCommand keyCommandWithInput:@"P" modifierFlags:UIKeyModifierCommand action:@selector(printNote:)];
    printNoteCommand.title = @"Print…";
    printNoteCommand.discoverabilityTitle = @"Print selected Note";
    
    UIMenu* printMenu = [UIMenu menuWithTitle:@"" image:nil identifier:@"com.tropic4.multinotes.printmenu" options: UIMenuOptionsDisplayInline children: @[printNoteCommand]];
    [builder insertChildMenu: printMenu atEndOfMenuForIdentifier: UIMenuFile ];
}

相关问题