I would like asking for advise to solve a little issue I have with a pop-up menu in a UICollectionViewController.
Inside the VC I have an action linked to a gesture "long press". When I long press inside a cell of the controller the action get triggered and the menu will be shown.
But: the menu is not modal/exclusive on the screen; it actually moves around while I keep the finger on the screen. A bit distracting.
What I would like to have is that the menu become fixed and only disappear after a function is selected or clicked outside the menu once.
Here a slightly changed piece of code I use.
Inside the VC I have an action linked to a gesture "long press". When I long press inside a cell of the controller the action get triggered and the menu will be shown.
But: the menu is not modal/exclusive on the screen; it actually moves around while I keep the finger on the screen. A bit distracting.
What I would like to have is that the menu become fixed and only disappear after a function is selected or clicked outside the menu once.
Here a slightly changed piece of code I use.
Code:
- (IBAction)handleLongPress:(id)sender
{
UILongPressGestureRecognizer *lp = sender;
CGPoint p = [lp locationInView:lp.view];
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:p];
if (indexPath != nil)
{
[self becomeFirstResponder];
MyUIMenuItem *f1 = [[MyUIMenuItem alloc] initWithTitle:@"f1" action:@selector(function1)];
MyUIMenuItem *f2 = [[MyUIMenuItem alloc] initWithTitle:@"f2" action:@selector(function2)];
MyUIMenuItem *f3 = [[MyUIMenuItem alloc] initWithTitle:@"f3" action:@selector(function3)];
MyUIMenuItem *f4 = [[MyUIMenuItem alloc] initWithTitle:@"f4" action:@selector(function4)];
UIMenuController * menu = [UIMenuController sharedMenuController];
menu.menuItems = [NSArray arrayWithObjects: f1, f2, f3, f4, nil];
[menu setTargetRect: CGRectMake(p.x, p.y, 0, 00) inView: lp.view.superview];
[menu setArrowDirection:UIMenuControllerArrowUp];
[menu setMenuVisible: YES animated: YES];
[menu update];
}
}