在单击uicollectionviewcell时,我希望使用与菜单栏相同的外观,如下所示:

但是,我想写动词而不是剪切

可能吗?我看到了一些答案-但他们都要求实现我自己的UIActionSheet-但我希望它看起来像菜单而不是操作表

可能吗?

最佳答案

    UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(showMenu:)];
    longPressGesture.minimumPressDuration=0.4;
    [longPressGesture setDelegate:self];
    [self.collectionCell addGestureRecognizer:longPressGesture];

- (void) showMenu:(UILongPressGestureRecognizer *)gestureRecognizer
{

    if ([gestureRecognizer state] == UIGestureRecognizerStateEnded) {

          UIMenuController *menuController = [UIMenuController sharedMenuController];
            UIMenuItem *menuItem1 = [[UIMenuItem alloc] initWithTitle:@"Cut" action:@selector(copyAction:)];
            UIMenuItem *menuItem3 = [[UIMenuItem alloc] initWithTitle:@"Paste" action:@selector(pasteAction)];
            CGPoint location = [gestureRecognizer locationInView:[gestureRecognizer view]];

            [menuController setMenuItems:[NSArray arrayWithObjects: menuItem1, menuItem1,nil]];
            [menuController setTargetRect:CGRectMake(location.x, location.y, 0, 0) inView:[gestureRecognizer view]];
            [menuController setMenuVisible:YES animated:YES];

               [self becomeFirstResponder];


    }
}

10-08 05:57