The solution that UIMenuController cannot be displayed inside the Cell ., Solution for internal version 7601
Xcode7.2, in iOS9.2 Environment
Try to add the LongPress gesture inside CollectionViewCell to display UIMenuController.
@ Implementation CollectionViewCell // inherits from UICollectionViewCell UILongPressGestureRecognizer * longPress = [[initalloc] initWithTarget: self action: @ selector (longPress :)]; longPress. minimumPressDuration = 1; [self addGestureRecognizer: longPress]; // Add long-pressed gesture // implement the long-pressed method-(void) longPress :( UILongPressGestureRecognizer *) gesture {switch (gesture. state) {case when: {// must implement [self becomeFirstResponder]; UIMenuController * menu = [UIMenuController sharedMenuController]; UIMenuItem * item1 = [[UIMenuItem alloc] initWithTitle: @ "save" action: @ selector (savePic)]; menu. menuItems = [NSArray arrayWithObject: item1]; [menu setTargetRect: self. scView. frame inView: self. scView. superview]; [menu setMenuVisible: YES animated: YES];} break; default: break ;}}
// Required method. Note that it is not the-(void) becomeFirstResponse method. -(Void) canBecomeFirstResponse {return YES ;}
After the above Code is implemented, the UIMenuController can be displayed when the cell is pressed for a long time. But one problem is that when I slide CollectionView, the menu is not hidden for the first time.
Therefore, you can hide the menu inside the method. Implement the following code.
UIMenuController * menu = [UIMenuController sharedMenuController];
[Menu setMenuVisible: NO animated: NO];