Under the xcode7.2,ios9.2 environment
Try to add longpress gestures inside the Collectionviewcell to show Uimenucontroller.
@implementation Collectionviewcell//Inherit from Uicollectionviewcell uilongpressgesturerecognizer *longpress = [[ Uilongpressgesturerecognizer Alloc] initwithtarget:self action: @selector (longpress:)]; Longpress.minimumpressduration = 1; [Self addgesturerecognizer:longpress];//add long press gesture//Implement long press Method-(void) Longpress: (Uilongpressgesturerecognizer *) gesture{ Switch (gesture.state) {case Uigesturerecognizerstatebegan: {//must implement [self becomefirstres Ponder]; 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; }}
// the method that must be implemented, note that the Becomefirstresponse method is not-(void). -(void) canbecomefirstresponse{ return YES;
By implementing the above code, you can display Uimenucontroller while long pressing the cell. But one problem is that when I swipe collectionview, the menu doesn't hide the first time.
So, it can be inside the method you need to hide the menu. Implement the following code.
Uimenucontroller *menu = [Uimenucontroller Sharedmenucontroller];
[Menu Setmenuvisible:no Animated:no];
Uimenucontroller The solution cannot be displayed inside the cell.