IOS Study Notes 37 -- UIPasteboard/UIMenuController (3)

Source: Internet
Author: User

This summary summarizes the use of the custom clipboard.

In fact, the custom clipboard is also very simple, it is nothing more than releasing the response time, using UIMenuController to customize the clipboard, and then the most critical implementation of the copy method you use to pull.

For convenience and practicality, I added a long-press event to the cell and read the code ---


UILongPressGestureRecognizer * recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPress :)];

[Cell addGestureRecognizer: recognizer];

Okay, the event is added, and the remaining click is to implement the custom clipboard. The Code is as follows:


-(Void) longPress :( UILongPressGestureRecognizer *) recognizer {

If (recognizer. state = UIGestureRecognizerStateBegan ){

CopyCell * cell = (CopyCell *) recognizer. view;

[Cell becomeFirstResponder];

UIMenuItem * flag = [[UIMenuItem alloc] initWithTitle: @ "Flag" action: @ selector (flag :)];

UIMenuItem * approve = [[UIMenuItem alloc] initWithTitle: @ "Approve" action: @ selector (approve :)];

UIMenuItem * deny = [[UIMenuItem alloc] initWithTitle: @ "Deny" action: @ selector (deny :)];

UIMenuController * menu = [UIMenuController sharedMenuController];

 


[Menu setMenuItems: [NSArray arrayWithObjects: flag, approve, deny, nil];

 


NSLog (@ "... % @", NSStringFromCGRect (cell. frame ));

[Menu setTargetRect: cell. frame inView: cell. superview];

 


[Menu setMenuVisible: YES animated: YES];

}

}

Through the above Code, the custom clipboard is successfully completed, run, you will suddenly find that, fuck, how did the Clipboard not come out, I guess you already think of why, because
-(BOOL) canBecomeFirstResponder {

Return YES;

}

There is no such important sentence. OK. The following is the method you want to use.

-(Void) flag :( id) sender {

 


NSLog (@ "Cell was flagged ");

 


}

-(Void) approve :( id) sender {

 


NSLog (@ "Cell was approved ");

}

 


-(Void) deny :( id) sender {

 


NSLog (@ "Cell was denied ");

 


}

Well, this is the basic clipboard customization. To make it more intuitive, the above three articles are similar to one of the following:

 

 
 

 

 

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.