一个接一个地显示UIMenuController的问题

一个接一个地显示UIMenuController的问题

本文介绍了一个接一个地显示UIMenuController的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIMenuController的新自定义功能将复制以外的内容添加到剪切和粘贴到网页视图的菜单中。

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.

我是什么do是获取对共享UIMenuController的引用,将我的NSArray的UIMenuItems设置为menuItems,只要我添加一个项目,一切正常。例如,我看到[COPY | FOOBAR]。

What I do is getting the reference to the shared UIMenuController, setting my NSArray of UIMenuItems into the menuItems, and everything work fine as long as I add a single item. For instance I see [COPY|FOOBAR].

相反,如果我尝试添加多个项目,那么我会看到[复制|更多],如果我按下进入超过最终其他项目将显示。

Instead if I try adding more than a single item, what happen is that I see [COPY|MORE], if I press into MORE than finally the other items will show up.

可以直接显示[COPY | FOO | BAR | THREE | FOUR]而不是?我看到了一些能够做到这一点的应用程序,尤其是iBooks。

Is possible to show directly [COPY|FOO|BAR|THREE|FOUR] instead? I saw a few applications that are able to do this, notably iBooks.

任何帮助非常有用,谢谢。

Any help very appreaciated, thank you.

干杯,
sissensio

Cheers,sissensio

推荐答案

fluXa的答案实际上是正确的,但我不认为这很清楚。

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

问题是当将自定义UIMenuItem对象添加到共享菜单控制器([UIMenuController sharedMenuController])时,只有第一个自定义UIMenuItem将显示在菜单。如果用户点击更多...,将显示剩余的自定义菜单项。

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...".

但是,如果菜单中不包含任何内置菜单项系统菜单项(复制:,粘贴:等),初始菜单显示将显示所有自定义菜单项,没有更多...项。

如果需要包含内置系统项,只需添加具有相同标题但具有不同选择器的自定义UIMenuItem。 (myCopy:与副本:)

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: )

基本上归结为不调用canPerformAction的默认实现:withSender:,显式处理所有自定义菜单项,并返回NO所有其他(系统提供的)菜单项:

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;
}

这篇关于一个接一个地显示UIMenuController的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:35