首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIMenuController未显示

UIMenuController未显示
EN

Stack Overflow用户
提问于 2018-11-08 06:13:48
回答 2查看 122关注 0票数 0

我正在尝试让UIMenuController显示一个菜单。

以下是我到目前为止拥有的代码:

代码语言:javascript
复制
commentCell.userInteractionEnabled = YES;
[commentCell becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
    return;
}
menu.menuItems = @[[[UIMenuItem alloc] initWithTitle:@"copy" action:@selector(log)], [[UIMenuItem alloc] initWithTitle:@"report" action:@selector(log)]];
const CGRect targetFrame = commentCell.frame;
const CGRect convertedFrame = [commentCell convertRect:targetFrame toView:self.viewController.view];
[menu setTargetRect:convertedFrame inView:self.viewController.view];
[menu update];
[menu setMenuVisible:YES animated:YES];

不幸的是,我的菜单似乎没有显示出来。我试图遵循UIMenuController not showing up中概述的指导原则,但我已经尝试了所有的建议,包括使我的视图实现canBecomeFirstResponder和将userInteractionEnabled设置为YES。有什么想法可能是这个问题,或者我可以如何进一步调试?

EN

回答 2

Stack Overflow用户

发布于 2018-11-08 06:31:12

找到了问题所在。原来我还需要包含字段:self.viewController中的-(BOOL)canPerformAction

票数 0
EN

Stack Overflow用户

发布于 2018-11-08 07:11:55

我想添加一个问题,即targetFrame应该是:

const CGRect targetFrame = commentCell.bounds;

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53198670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档