Uimenucontroller The solution cannot be displayed inside the cell.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.