2

I have 2 locations on my app that I use a UILongPressGestureRecognizer to show a menu with 2 choices. The two locations, Left and Right, are UILabels that display numbers. A long press on the number will popup a menu with options to either "Reset to 0" or "Cancel".

I get the menu to popup without a problem. However, I've run into a problem after the menus are displayed: the display of RIGHT-SIDE menu items is cutoff, almost in half. I've included an image to help illustrate my problem (parts of the image are intentionally pixelated). The menu item works, it calls the correct method, it just doesn't display correctly. I have a call to -(BOOL)canBecomeFirstResponder {return YES;} later in the class.

Here's my code for the left-side menu:

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

Here's the code for the right-side menu:

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

fsb
  • 290
  • 10
  • 28
  • Does the left-side menu show both menu items? Do leftActionNameNumber and rightActionNameNumber have the same constraints, so their frames are the same width? – Mike Taverne Nov 26 '14 at 03:23
  • I also have a same problem. working in ios 7.1 sdk.... – Pratik B Nov 26 '14 at 05:10
  • @mike, yes to both your questions. It's only the right side that's cut off. I thought it might have to do with the frame width of 'self.rightActionNameNumber.frame' but even with a width that extends all the way to the right side of the app, the problem persists. – fsb Nov 26 '14 at 10:26
  • This is strange. On my iPhone 6 with 8.1, I get the same thing as I described above. On the simulator with all iPhone 5/5S & 7.1/8.1, the menu works perfectly (I don't have an iPhone 5/5S to test on actual device). On iPhone 6 Plus simulator, I don't get the popup menu at all (I don't have a 6 Plus device to test). – fsb Nov 26 '14 at 13:09
  • Also, I ran thru all permutations of simulators and it worked on some and not on others. I couldn't find a pattern with either device or iOS version. This is becoming very strange. – fsb Nov 26 '14 at 13:17
  • It sounds like you are seeing the issue on wider screens. If you change the "Reset to 0" text to something longer or shorter, what happens? Does the menu always truncate at the same location, or does the first menu item always display regardless of length? – Mike Taverne Nov 26 '14 at 20:49
  • Thanks for trying to help, @mike. I changed to text to something shorter & longer and still had the cutoff. Regarding your second question, the menu always cuts off at the same place regardless of what text I put in there. I thought it might have something to do with the Z order of the controls on the screen. I looked at that with the 3D-like view in Xcode and there's nothing in front of it that would block part of the menu. – fsb Nov 28 '14 at 16:37
  • Similar issue reported here http://stackoverflow.com/questions/26506437/iphone6-no-display-zoom-mode-uimenucontroller-truncated – Mike Taverne Nov 28 '14 at 19:03
  • I created a fresh project and had no problems displaying a menu at the far right edge on iPhone 6 and 6 Plus simulator. I tried with a storyboard that used size classes and one that did not. I could not repro the truncation issue. I would suspect something in your code is limiting the screen size to 320 and causing truncation on wider devices. – Mike Taverne Nov 28 '14 at 20:13
  • I appreciate you trying to help, @mike. I didn't see that other issue when I did my search but it looks like the same problem. I'm beginning to think that this is an iOS problem and that I can't solve it in code. – fsb Nov 29 '14 at 15:08

0 Answers0