The solution that UIMenuController cannot be displayed inside the Cell ., Solution for internal version 7601

Source: Internet
Author: User

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];

 

Related Article

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.