UIMenuController 在 iOS 4 上不显示,但在 iOS 5 上工作
在自定义视图中,我将“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先检查成为FirstResponder。
check becomeFirstResponder first.