(1)先设置下menu要显示的位置
Parameters
targetRect |
A rectangle that defines the area that is to be the target of the menu commands. |
targetView |
The view in which |
This target rectangle (targetRect
) is usually the bounding rectangle of a selection. UIMenuController
positions the editing menu above this rectangle; if there is not enough space for the menu there, it positions it below the rectangle. The menu’s pointer is placed at the center of the top or bottom of the target rectangle as appropriate. Note that if you make the width or height of the target rectangle zero, UIMenuController
treats the target area as a line or point for positioning (for example, an insertion caret or a single point).
Once it is set, the target rectangle does not track the view; if the view moves (such as would happen in a scroll view), you must update the target rectangle accordingly.(需要办法更新下菜单的位置)
Before showing the menu, be sure to position it relative to the selection. See setTargetRect:inView:
for details. If you do not set the target rect before displaying the menu, it appears at screen coordinates (0.0, 0.0).
(3)菜单箭头方向 typedef enum { UIMenuControllerArrowDefault, UIMenuControllerArrowUp, UIMenuControllerArrowDown, UIMenuControllerArrowLeft, UIMenuControllerArrowRight,} UIMenuControllerArrowDirection;
(4)几个回调通知
UIMenuControllerMenuFrameDidChangNotification
UIMenuControllerDidHideMenuNotification
UIMenuControllerWillHideMenuNotification
UIMenuControllerDidShowMenuNotification
UIMenuControllerWillShowMenuNotification
(5)自定义菜单 位置 menuIems[] = {UIMenuItem}
(6) Update
UIMenuControllerMenuFrameDidChangeNotification
-
Updates the appearance and enabled state of menu commands.
Declaration
OBJECTIVE-C
- (void)update
Discussion
By default,
UIMenuController
calls this method just before the editing menu is made visible and when touches occur in the menu. As a result, a responder object in the application enables or disables menu commands depending on the context; for example, if the pasteboard holds no data of a compatible type, the Paste command would be disabled. You can call this method to force an update of the editing menu. You may also override this method to add any custom behavior.