[Text Relatives II]
When your app determines that the user has requested the edit menu—which could be the action of making a selection—you should complete the following steps to display the menu:
-
Call the
sharedMenuControllerclass method ofUIMenuControllerto get the global menu-controller instance. -
Compute the boundaries of the selection and with the resulting rectangle call the
setTargetRect:inView:method. The edit menu is displayed above or below this rectangle, depending how close the selection is to the top or bottom of the screen. -
Call the
setMenuVisible:animated:method (withYESfor both arguments) to animate the display of the edit menu above or below the selection.
Displaying the edit menu:
1 - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 2 UITouch *theTouch = [touches anyObject]; 3 4 if ([theTouch tapCount] == 2 && [self becomeFirstResponder]) { 5 6 // selection management code goes here... 7 8 // bring up edit menu. 9 UIMenuController *theMenu = [UIMenuController sharedMenuController]; 10 CGRect selectionRect = CGRectMake (currentSelection.x, currentSelection.y, SIDE, SIDE); 11 [theMenu setTargetRect:selectionRect inView:self]; 12 [theMenu setMenuVisible:YES animated:YES]; 13 14 } 15 }