Problems showing UIMenuController one after another

前端 未结 4 883
鱼传尺愫
鱼传尺愫 2021-02-08 10:50

I\'m using the new customization abilities of the UIMenuController to add things other than \"Copy\" to the menu for cut&paste into a webview.

What I do is getting t

4条回答
  •  粉色の甜心
    2021-02-08 10:59

    fluXa's answer is actually correct, but I dont think it was very clear.

    The issue is that when adding custom UIMenuItem objects to the shared menu controller ([UIMenuController sharedMenuController]), only the first custom UIMenuItem will be shown on the initial display of the menu. The remaining custom menu items will be shown if the user taps "More...".

    However, if the menu doesn't include any built-in system menu items (copy:, paste:, etc), the initial menu display will show all custom menu items and no "More..." item.

    If you need to include the built-in system items, simply add custom UIMenuItems having the same title but with a different selector. ( myCopy: vs. copy: )

    Essentially it boils down to NOT calling the default implementation of canPerformAction:withSender:, explicitly handling all custom menu items, and returning NO for all other (system-supplied) menu items:

    - (BOOL) canPerformAction:(SEL)action withSender:(id)sender
    {
        if ( action == @selector( onCommand1: ) )
        {
            // logic for showing/hiding command1
            BOOL show = ...;
            return show;
        }
    
        if ( action == @selector( onCommand2: ) )
        {
            // logic for showing/hiding command2
            BOOL show = ...;
            return show;
        }
    
        if ( action == @selector( onCopy: ) )
        {
            // always show our custom "copy" command
            return YES;
        }   
    
        return NO;
    }
    

提交回复
热议问题