Uimenucontroller solutions that cannot be displayed inside the cell (iOS9.2) _ios

Source: Internet
Author: User

Under xcode7.2,ios9.2 Environment

Try to add longpress gestures inside the Collectionviewcell to show the Uimenucontroller.

@implementation Collectionviewcell//inherits from Uicollectionviewcell uilongpressgesturerecognizer *longpress = [[UILongPress
 Gesturerecognizer Alloc] initwithtarget:self action: @selector (longpress:)];
 Longpress.minimumpressduration = 1;
 [Self addgesturerecognizer:longpress];//add long press gesture//implementation long by Method-(void) Longpress: (Uilongpressgesturerecognizer *) gesture { Switch (gesture.state) {case Uigesturerecognizerstatebegan: {[Self Becomefirstresponder];<span style= Color:rgb (255, 0, 0); " >//must have!
  </span> 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; } <span style= "Color:rgb (0, 128, 0);" >//must be implemented. Note Not-(BOOL) Becomefirstresponder method </span>-(BOOL) CANBECOMEFIRSTRESPONDEr {return YES} 

 

By implementing the above code, you can display Uimenucontroller when the cell is long pressed. But one of the problems is that when I slide CollectionView, the menu doesn't hide the first time.
So you can do it inside the way you want the menu to hide. Implement the following code.
Uimenucontroller *menu = [Uimenucontroller Sharedmenucontroller];
[Menu Setmenuvisible:no Animated:no];

The above is uimenucontroller within the cell can not show the solution, I hope that the learning of everyone help, but also hope that we support the cloud habitat community.

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.