gpt4 book ai didi

iphone - UIMenuController 未显示

转载 作者:行者123 更新时间:2023-12-03 19:10:19 28 4
gpt4 key购买 nike

我在长按和双击手势上显示 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上获取这个事件,什么可以磨损。

最佳答案

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

- (BOOL) canBecomeFirstResponder 
{
return YES;
}

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

关于iphone - UIMenuController 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16054050/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com