【发布时间】:2016-03-03 20:37:23
【问题描述】:
在 UIWebView 中选择文本时,我使用以下代码在 UIMenuController 中显示自定义项。
//Custom UIMenuController actions for highlighting and commenting
UIMenuItem *highlightItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Highlight", nil) action:@selector(highlightAction:) image:[UIImage imageNamed:@"HighlightIcon"]];
UIMenuItem *commentItem = [[UIMenuItem alloc] initWithTitle:NSLocalizedString(@"Comment", nil) action:@selector(createCommentAction:) image:[UIImage imageNamed:@"CommentIcon"]];
[UIMenuController sharedMenuController].menuItems = @[highlightItem, commentItem];
[[UIMenuController sharedMenuController] update];
It works fine the first time and display only the two custom options I have, but after that whenever some text is selected it shows the native options first and the custom ones on the next page of items.
我想知道如何永久删除本机选项 - 所有其他问题和示例似乎不适用于 iOS 7+。
我也有这个用于启用菜单:
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(highlightAction:) ||
action == @selector(createCommentAction:) ||
return YES;
else if (action == @selector(copy:))
{
return NO;
}
return [super canPerformAction:action withSender:sender];
}
#pragma mark - privates
- (void)pressme:(id)sender
{
[[UIMenuController sharedMenuController] setTargetRect:[sender frame] inView:self.view];
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:YES];
[[UIMenuController sharedMenuController] update];
}
【问题讨论】:
标签: ios objective-c xcode uiwebview uimenucontroller