How does the iphone display menus and perform copy operations?

Source: Internet
Author: User

How does the iphone display menus and perform copy operations?

 

1. First, you must display the menu

 

// First turn yourself into the first response <br/> [self becomeFirstResponder]; <br/> // obtain the menu Controller <br/> UIMenuController * copyMenuController = [UIMenuController sharedMenuController]; </p> <p> // set the display position <br/> [copyMenuController setTargetRect: CGRectMake (15, 15,100, 50) inView: self. view]; <br/> // display <br/> [copyMenuController setMenuVisible: YES animated: YES]; </p> <p> 

 

2. Then, you need to change your ViewController to firstResponder.

 

RESPONSE:-(BOOL) canBecomeFirstResponder

 

-(BOOL) canBecomeFirstResponder <br/>{< br/> return YES; <br/>} 

 

3. RESPONSE:-(BOOL) can1_maction :( SEL) action withSender :( id) sender

 

-(BOOL) can1_maction :( SEL) action withSender :( id) sender <br/>{< br/> BOOL retValue = NO; <br/> if (action ==@ selector (copy :)) <br/>{< br/> NSLog (@ "can1_maction"); <br/> retValue = YES; <br/>}< br/> else if (action = @ selector (paste :)) <br/>{< br/> NSLog (@ "canPerformAction "); <br/> retValue = NO; <br/>}< br/> else <br/>{< br/> retValue = [super can1_maction: action withSender: sender]; <br/>}</p> <p> return retValue; <br/>} 

 

4. Execute the copy operation

 

// Perform the copy operation <br/>-(void) copy :( id) sender <br/>{< br/> UIPasteboard * gpBoard = [UIPasteboard generalPasteboard]; <br/> if (gpBoard) <br/>{< br/> NSString * copytext = @ "text"; <br/> [gpBoard setString: copytext]; <br/>}</p> <p>} 

The above Code places the "text" string in the system clipboard.

 

 

 

 

 


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.