UIMenuController 在 iOS 4 上不显示,但在 iOS 5 上工作

发布于 2024-12-12 18:17:57 字数 935 浏览 0 评论 0原文

在自定义视图中,我将“canBecomeFirstResponder”设置为返回 YES 并且还定义了 '- (BOOL)canPerformAction:(SEL)action withSender:(id)sender'

我使用以下代码来显示弹出菜单:

[self becomeFirstResponder];
UIMenuController *theMenu = [UIMenuController sharedMenuController];


if (theMenu.menuItems==nil)
{
    UIMenuItem* item = [[UIMenuItem alloc] initWithTitle:@"Open" action:@selector(openAction:)];
    NSArray* array = [NSArray arrayWithObject:item];
    theMenu.menuItems = array;
    [item release];
}

CGRect rect;
rect = CGRectMake(self.frame.size.width*0.5, self.frame.size.height*0.5, 0, 0);
[theMenu setTargetRect:rect inView:self];
theMenu.arrowDirection = UIMenuControllerArrowDown;
[theMenu setMenuVisible:YES animated:YES];

问题是这在 iOS 5 上工作正常 但在 iOS 4.3 上不显示任何内容。

然而,在两个 iOS 上,“UIMenuControllerWillShowMenuNotification” 并收到“UIMenuControllerDidShowMenuNotification”通知 正如预期的那样。

任何人都可以帮助或指出我正确的方向吗? 提前致谢。

In a custom view i have set 'canBecomeFirstResponder' to return YES
and have also defined '- (BOOL)canPerformAction:(SEL)action withSender:(id)sender'

I use the following code to display the popup menu:

[self becomeFirstResponder];
UIMenuController *theMenu = [UIMenuController sharedMenuController];


if (theMenu.menuItems==nil)
{
    UIMenuItem* item = [[UIMenuItem alloc] initWithTitle:@"Open" action:@selector(openAction:)];
    NSArray* array = [NSArray arrayWithObject:item];
    theMenu.menuItems = array;
    [item release];
}

CGRect rect;
rect = CGRectMake(self.frame.size.width*0.5, self.frame.size.height*0.5, 0, 0);
[theMenu setTargetRect:rect inView:self];
theMenu.arrowDirection = UIMenuControllerArrowDown;
[theMenu setMenuVisible:YES animated:YES];

The problem is that this works fine on iOS 5
but doesn't show anything on iOS 4.3.

However on BOTH iOSes the 'UIMenuControllerWillShowMenuNotification'
and the 'UIMenuControllerDidShowMenuNotification' notifications are received
as expected.

Can anyone help or point me to the right direction please.
Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈场末日恋爱 2024-12-19 18:17:58
 if(![self becomeFirstResponder]; )
 {
    NSLog(@"Couldn't become first responder ");
    return;
 }

首先检查成为FirstResponder。

 if(![self becomeFirstResponder]; )
 {
    NSLog(@"Couldn't become first responder ");
    return;
 }

check becomeFirstResponder first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文