iPhone / iPad上下文菜单 [英] iPhone/iPad context menu

查看:66
本文介绍了iPhone / iPad上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在谈论当您选择文本块时显示的菜单,它为您提供剪切/粘贴/复制选项。我想出了如何在菜单中添加一个选项,但如果我添加两个或更多选项,它将首先说更多。点击它将显示我添加的所有选项。但有没有办法显示我提前添加的所有选项?没有更多菜单项?

Im talking about the menu that shows up when you select a block of text it gives you the option to cut/paste/copy. I figured out how to add one more option to the menu, but if I add two or more options it will say "more" first. clicking it will show all the options I added. But is there a way to show all the options I added upfront? without the "more" menu item?

推荐答案

你需要使用 UIMenuController 。如果您不想复制/粘贴/剪切,您将在 canPerformAction:方法中包含类似的内容:

You need to use a UIMenuController. If you don't want Copy/Paste/Cut, you'll include something like this in your canPerformAction: method:

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
     if(action == @selector(someSelector:))
         return YES;
     else 
         return NO;
}

创建一个新菜单项如下所示:

Creating a new menu item looks like this:

UIMenuItem *someAction = [[UIMenuItem alloc]initWithTitle:@"Something" action:@selector(doSomething:)];

UIMenuController *menu = [UIMenuController sharedMenuController];
menu.menuItems = [NSArray arrayWithObject:someAction];
[menu update];

这篇关于iPhone / iPad上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆