iPhone是menuCont.arrowDirection = UIMenuControllerArrowDown;不工作的错误? [英] iPhone, is menuCont.arrowDirection = UIMenuControllerArrowDown; not working a bug?

查看:31
本文介绍了iPhone是menuCont.arrowDirection = UIMenuControllerArrowDown;不工作的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

点击标签栏后,我试图添加菜单控制器作为选项的快速选择,但是使用时我没有得到箭头

I'm trying to add a menu controller as a quick choice of options after tapping my tab bar, however I don't get the arrow, when I use

menuCont.arrowDirection = UIMenuControllerArrowDown;

但是,如果我使用向上,向左或向右,则效果很好.

But if I use Up, Left or Right it works fine.

其他人可以尝试一下并提出建议吗?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event allTouches] anyObject];

if ([touch tapCount] == 2) {
    [self becomeFirstResponder];
    UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Blue" action:@selector(blueView)];
    UIMenuItem *menuItem2 = [[UIMenuItem alloc] initWithTitle:@"Green" action:@selector(greenView)];
    UIMenuItem *menuItem3 = [[UIMenuItem alloc] initWithTitle:@"Red" action:@selector(redView)];

    UIMenuController *menuCont = [UIMenuController sharedMenuController];
    [menuCont setTargetRect:CGRectMake(0,0,320,200) inView:self.view];
    menuCont.menuItems = [NSArray arrayWithObjects:menuItem, menuItem2, menuItem3, nil];
    menuCont.arrowDirection = UIMenuControllerArrowDown;
    [menuCont setMenuVisible:YES animated:YES];
}
}

- (void)blueView {
self.view.backgroundColor = [UIColor blueColor];
}
- (void)greenView {
self.view.backgroundColor = [UIColor greenColor];
}
- (void)redView {
self.view.backgroundColor = [UIColor redColor];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
BOOL answer = NO;

if (action == @selector(blueView)) 
    answer = YES;

if (action == @selector(greenView)) 
    answer = YES;

if (action == @selector(redView)) 
    answer = YES;

return answer;
}

- (BOOL)canBecomeFirstResponder {
return YES;
}

PS.我想知道它是否过时,因为在输入某些菜单控制器代码时它不会自动完成?

PS. I'm wondering if its old school, as it doesn't auto-complete when entering some of the menu controller code ?

推荐答案

请参阅UIMenuController的文档.

see the Documentation of the UIMenuController.

setTargetRect:inView:
将区域设置在在其上方或下方的视图定位编辑菜单.

setTargetRect:inView:
Sets the area in a view above or below which the editing menu is positioned.

这意味着,如果您指定从x = 0 y = 0开始的rect,并且想要downArrow,则程序会尝试在rect上方绘制菜单.这是不可能的,因为UIMenus始终位于屏幕的可见区域中.

which means, if you specify a rect starting at x=0 y=0, and you want a downArrow, the program tries to draw the Menu above your rect. And this is not possible because UIMenus are always in the visible area of the screen.

使用 [menuCont setTargetRect:CGRectMake(0,100,320,200)inView:self.view]; 并查看向下箭头

这篇关于iPhone是menuCont.arrowDirection = UIMenuControllerArrowDown;不工作的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆