Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:UIMenuItem菜单截止_Ios_Objective C_Xcode6_Uimenuitem - Fatal编程技术网

iOS:UIMenuItem菜单截止

iOS:UIMenuItem菜单截止,ios,objective-c,xcode6,uimenuitem,Ios,Objective C,Xcode6,Uimenuitem,我的应用程序上有两个位置,我使用UILongPressGestureRecognitor来显示包含两个选项的菜单。左右两个位置是显示数字的UILabel。长按该号码将弹出一个菜单,其中包含“重置为0”或“取消”选项 我可以毫无问题地弹出菜单。然而,在显示菜单后,我遇到了一个问题:右侧菜单项的显示被切断,几乎一半。我已经包括了一个图像来帮助说明我的问题(图像的部分被有意地像素化)。菜单项起作用,它调用了正确的方法,只是显示不正确。我有一个调用-(BOOL)canBecomeFirstRespond

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

我可以毫无问题地弹出菜单。然而,在显示菜单后,我遇到了一个问题:右侧菜单项的显示被切断,几乎一半。我已经包括了一个图像来帮助说明我的问题(图像的部分被有意地像素化)。菜单项起作用,它调用了正确的方法,只是显示不正确。我有一个调用
-(BOOL)canBecomeFirstResponder{returnyes;}
,稍后在类中调用

这是我的左侧菜单代码:

- (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];

}
下面是右侧菜单的代码:

- (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];

}

左侧菜单是否同时显示这两个菜单项?leftActionNameNumber和rightActionNameNumber是否具有相同的约束,因此它们的帧宽度相同?我也有相同的问题。在ios 7.1 sdk中工作…@mike,两个问题都是。只有右边被切断了。我认为这可能与“self.rightActionNameNumber.frame”的帧宽有关,但即使宽度一直延伸到应用程序的右侧,问题仍然存在。这很奇怪。在我的iPhone6和8.1上,我得到了与上面描述的相同的东西。在所有iphone5/5S和7.1/8.1的模拟器上,菜单工作得非常好(我没有iphone5/5S可以在实际设备上测试)。在iPhone6plus模拟器上,我根本没有弹出菜单(我没有一个6plus设备要测试)。此外,我运行了所有模拟器的排列,它在一些模拟器上工作,而在其他模拟器上没有工作。我找不到设备或iOS版本的模式。这变得很奇怪。