UIMenuController

鉴于方便起见,直接介绍一种方便的方法

    一、添加

  

    UIMenuController *menuController = [UIMenuController sharedMenuController];
        [menuController setMenuVisible:YES animated:YES];
       //添加需要展示的条目
        UIMenuItem *item = [[UIMenuItem alloc] initWithTitle:@"reset" action:@selector(reset:)];
        UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"reset" action:@selector(reset:)];
        NSArray *array = [NSArray arrayWithObjects:item,item2, nil];
        menuController.menuItems = array;
        [self becomeFirstResponder];
        CGPoint point = [gesture locationInView:gesture.view];
         //设置要添加的左边及视图
        [menuController setTargetRect:CGRectMake(point.x, point.y, 100, 40)     inView:gesture.view];

 二、在要添加的视图,或者其superview中重写

- (BOOL)canBecomeFirstResponder

{

    return YES;

}

三、调用

   

        [self becomeFirstResponder];

         

你可能感兴趣的:(UIMenuController)