5

我在长按和双击手势上显示 UIMenuController,但它没有显示。我已经按照这里给出的答案,但它仍然没有出现。UIMenuController 没有出现

下面是我的代码

- (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 上获取此事件,可以穿什么。

4

1 回答 1

6

我终于通过在我的代码中添加以下方法解决了我的问题

- (BOOL) canBecomeFirstResponder 
{
     return YES; 
}

您还必须实现所有按钮的操作。否则,该特定按钮将不会显示在菜单中。

于 2013-04-17T08:10:06.380 回答