首先,这四个地图。我想实现的功能。【一张照片讲一个复制到另一UIimageView上】
实现代码例如以下:
-(IBAction)panGestureTop:(UILongPressGestureRecognizer *)longPress { UIMenuItem * itemPase = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyimage)]; UIMenuItem * itemTrans = [[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(trans)]; UIMenuItem * itemCollect = [[UIMenuItem alloc] initWithTitle:@"收藏" action:@selector(collect)]; UIMenuItem * itemJoin = [[UIMenuItem alloc] initWithTitle:@"增加" 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 = UIMenuControllerArrowDown; [menuController setMenuVisible:YES animated:YES]; } -(BOOL)canBecomeFirstResponder { return YES; } -(void)copyimage { UIPasteboard * pasterBoard = [UIPasteboard pasteboardWithName:@"com.test.image" create:YES]; pasterBoard.image = [self.topImgView image]; } -(IBAction)panGestureBottom:(UILongPressGestureRecognizer *)longPress { UIMenuItem * itemPase = [[UIMenuItem alloc] initWithTitle:@"粘贴" action:@selector(pase)]; UIMenuController * menuController = [UIMenuController sharedMenuController]; [menuController setMenuItems: @[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:@"com.test.image" create:NO]; self.bottomImgView.image = pasterBoard.image; }
当操作的时候。我们须要把当前的UIViewController变成第一响应者。
复制相当于copy了一份,增加我在复制过图片之后,粘贴图片之前,把原来的那个image删除掉。则依旧能够进粘贴行。
版权声明:本文博客原创文章。博客,未经同意,不得转载。