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.