UIMenuController没有得到显示(UIMenuController not gettin

2019-08-31 08:40发布

我长按和双击手势显示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这种情况下,有什么可以拨错。

Answer 1:

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

- (BOOL) canBecomeFirstResponder 
{
     return YES; 
}

你还必须实现所有按钮的操作。 其他特定按钮不会显示在菜单中。



文章来源: UIMenuController not getting displayed