Uimenucontroller and uipasteboard: copy and paste details

Source: Internet
Author: User

First, use the following four pictures to illustrate the functions I want to implement. [Copy an image to another uiimageview]



The implementation code is as follows:

-(Ibaction) pangesturetop :( uilongpressgesturerecognizer *) longpress {uimenuitem * itempase = [[uimenuitem alloc] initwithtitle: @ "copy" Action: @ selector (copyimage)]; uimenuitem * itemtrans = [[uimenuitem alloc] initwithtitle: @ "Forward" Action: @ selector (trans)]; uimenuitem * itemcollect = [[uimenuitem alloc] initwithtitle: @ "add to Favorites" Action: @ selector (collect)]; uimenuitem * itemjoin = [[uimenuitem alloc] initwithtitle: @ "add" Action: @ selector (join)]; uimenucontroller * menucontroller = [uimenucontroller sharedmenucontroller]; [menucontroller setmenuitems: @ [itempase, itemcollect, itemtrans, itemjoin]; cgpoint location = [longpress locationinview: [longpress view]; cgrect menulocation = cgrectmake (location. x, location. y, 0, 0); [menucontroller settargetrect: menulocation inview: [longpress view]; menucontroller. arrowdirection = require; [menucontroller setmenuvisible: Yes animated: Yes];}-(bool) returns {return yes;}-(void) copyimage {uipasteboard * pasterboard = [uipasteboard pasteboardwithname: @ "com. test. image "create: Yes]; pasterboard. image = [self. topimgview image];}-(ibaction) pangesturebottom :( screenshot *) longpress {uimenuitem * itempase = [[uimenuitem alloc] initwithtitle: @ "Paste" Action: @ selector (PASE)]; uimenucontroller * menucontroller = [uimenucontroller sharedmenucontroller]; [menucontroller region: @ [itempase]; cgpoint location = [longpress locationinview: [longpress view]; cgrect menulocation = cgrectmake (location. x, location. y, 0, 0); [menucontroller settargetrect: menulocation inview: [longpress view]; menucontroller. arrowdirection = uimenucontrollerarrowdown; [menucontroller setmenuvisible: Yes animated: Yes];}-(void) PASE {uipasteboard * pasterboard = [uipasteboard pasteboardwithname. test. image "create: No]; self. bottomimgview. image = pasterboard. image ;}

During the operation, we need to change the current uiviewcontroller to the first responder.


Copying is equivalent to copying a copy. After copying an image, you can still paste it if you delete the original image before pasting it.



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.