UIMenuController 未显示
Posted
技术标签:
【中文标题】UIMenuController 未显示【英文标题】:UIMenuController not getting displayed 【发布时间】:2013-04-17 07:26:00 【问题描述】:我在长按和双击手势时显示 UIMenuController,但它没有显示。我已经按照这里给出的答案,但它仍然没有出现。 UIMenuController not showing up
下面是我的代码
- (void) doubleTap:(UITapGestureRecognizer *)gesture
[self becomeFirstResponder];
CGPoint location = [gesture locationInView:[gesture view]];
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *resetMenuItem = [[UIMenuItem alloc] initWithTitle:@"DoubleTap" action:@selector(hideKeyboard)];
[menuController setMenuItems:[NSArray arrayWithObject:resetMenuItem]];
[menuController setTargetRect:CGRectMake(location.x, location.y, 0.0f, 0.0f) inView:[gesture view]];
[menuController setMenuVisible:YES animated:YES];
- (void) longPress:(UITapGestureRecognizer *)gesture
[self becomeFirstResponder];
CGPoint location = [gesture locationInView:[gesture view]];
UIMenuController *menuController = [UIMenuController sharedMenuController];
UIMenuItem *resetMenuItem = [[UIMenuItem alloc] initWithTitle:@"LongPress" action:@selector(hideKeyboard)];
[menuController setMenuItems:[NSArray arrayWithObject:resetMenuItem]];
[menuController setTargetRect:CGRectMake(location.x, location.y, 0.0f, 0.0f) inView:[gesture view]];
[menuController setMenuVisible:YES animated:YES];
- (BOOL)becomeFirstResponder
return YES;
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
if (action == @selector(copy:))
return YES;
return [super canPerformAction:action withSender:sender];
我正在尝试在 tableView 的 didSelectRow 上获取此事件,可以穿什么。
【问题讨论】:
【参考方案1】:我终于通过在我的代码中添加以下方法解决了我的问题
- (BOOL) canBecomeFirstResponder
return YES;
您还必须实现所有按钮的操作。否则,该特定按钮将不会显示在菜单中。
【讨论】:
任何以前在 ios6 上工作的菜单在 iOS7 上不工作的人?以上是关于UIMenuController 未显示的主要内容,如果未能解决你的问题,请参考以下文章
UIMenuController setTargetRect 详细信息