iOS:UIMenuItem菜单截止

时间:2014-11-26 00:11:45

标签: ios objective-c xcode6 uimenuitem

我的应用上有2个位置,我使用UILongPressGestureRecognizer来显示包含2个选项的菜单。左侧和右侧两个位置是显示数字的UILabel。长按该号码将弹出一个菜单,其中包含“重置为0”或“取消”的选项。

我的菜单弹出没有问题。但是,在菜单显示后我遇到了问题:RIGHT-SIDE菜单项的显示被截止,几乎是一半。我已经包含了一个图像来帮助说明我的问题(图像的某些部分是故意像素化的)。菜单项有效,它调用正确的方法,它只是无法正确显示。我在课堂后面打电话给-(BOOL)canBecomeFirstResponder {return YES;}

这是左侧菜单的代码:

- (IBAction)leftActionLongPress:(UILongPressGestureRecognizer*)recognizer
{
// On a long press, show popup menu with selections to reset the number to
// zero or not

[self.leftActionNameNumber canBecomeFirstResponder];

// Check if the number is not a zero
if ([self.leftActionNameNumber.text isEqualToString:@"0"]) {
    // Equal to zero so don't show the popup menu
    return;
} else {
    // Number is not a zero, show popup menu
    UIMenuItem* resetMenu =
        [[UIMenuItem alloc] initWithTitle:@"Reset to 0"
                                   action:@selector(resetLeftToZero)];
    UIMenuItem* cancelMenu =
        [[UIMenuItem alloc] initWithTitle:@"Cancel"
                                   action:@selector(leaveNumberAsIs)];

    UIMenuController* menu = [UIMenuController sharedMenuController];
    [menu setMenuItems:[NSArray arrayWithObjects:resetMenu, cancelMenu, nil]];
    [menu setTargetRect:self.leftActionNameNumber.frame inView:self.view];
    [menu setMenuVisible:YES animated:YES];
}

以下是右侧菜单的代码:

- (IBAction)rightActionLongPress:(UILongPressGestureRecognizer*)recognizer
{
// On a long press, show popup menu with selections to reset the number to
// zero or not

[self.rightActionNameNumber canBecomeFirstResponder];


// Check if the number is not a zero
if ([self.rightActionNameNumber.text isEqualToString:@"0"]) {
    // Equal to zero so don't show the popup menu
    return;
} else {
    // Number is not a zero, show popup menu
    UIMenuItem* resetMenu =
        [[UIMenuItem alloc] initWithTitle:@"Reset to 0"
                                   action:@selector(resetRightToZero)];
    UIMenuItem* cancelMenu =
        [[UIMenuItem alloc] initWithTitle:@"Cancel"
                                   action:@selector(leaveNumberAsIs)];

    UIMenuController* menu = [UIMenuController sharedMenuController];
    [menu setMenuItems:[NSArray arrayWithObjects:resetMenu, cancelMenu, nil]];
    [menu setTargetRect:self.rightActionNameNumber.frame inView:self.view];
    [menu setMenuVisible:YES animated:YES];

}

Image displaying UIMenuItem with cut-off menu

0 个答案:

没有答案