UIMenuController

UIMenuController_第1张图片UIMenuController_第2张图片UIMenuController_第3张图片UIMenuController_第4张图片

实现代码如下:

 

view source print ?
01. -(IBAction)panGestureTop:(UILongPressGestureRecognizer *)longPress
02. {
03.  
04. UIMenuItem * itemPase = [[UIMenuItem alloc] initWithTitle:@"复制" action:@selector(copyimage)];
05. UIMenuItem * itemTrans = [[UIMenuItem alloc] initWithTitle:@"转发" action:@selector(trans)];
06. UIMenuItem * itemCollect = [[UIMenuItem alloc] initWithTitle:@"收藏" action:@selector(collect)];
07. UIMenuItem * itemJoin = [[UIMenuItem alloc] initWithTitle:@"加入" action:@selector(join)];
08.  
09. UIMenuController * menuController = [UIMenuController sharedMenuController];
10. [menuController setMenuItems: @[itemPase,itemCollect,itemTrans,itemJoin]];
11.  
12. CGPoint location = [longPress locationInView:[longPress view]];
13. CGRect menuLocation = CGRectMake(location.x, location.y, 00);
14. [menuController setTargetRect:menuLocation inView:[longPress view]];
15. menuController.arrowDirection = UIMenuControllerArrowDown;
16.  
17. [menuController setMenuVisible:YES animated:YES];
18.  
19. }
20. -(BOOL)canBecomeFirstResponder
21. {
22. return YES;
23. }
24.  
25. -(void)copyimage
26. {
27.  
28. UIPasteboard * pasterBoard = [UIPasteboard pasteboardWithName:@"com.test.image" create:YES];
29. pasterBoard.image = [self.topImgView image];
30.  
31. }
32. -(IBAction)panGestureBottom:(UILongPressGestureRecognizer *)longPress
33. {
34. UIMenuItem * itemPase = [[UIMenuItem alloc] initWithTitle:@"粘贴" action:@selector(pase)];
35.  
36. UIMenuController * menuController = [UIMenuController sharedMenuController];
37. [menuController setMenuItems: @[itemPase]];
38.  
39. CGPoint location = [longPress locationInView:[longPress view]];
40. CGRect menuLocation = CGRectMake(location.x, location.y, 00);
41. [menuController setTargetRect:menuLocation inView:[longPress view]];
42. menuController.arrowDirection = UIMenuControllerArrowDown;
43.  
44. [menuController setMenuVisible:YES animated:YES];
45.  
46. }
47. -(void)pase
48. {
49. UIPasteboard * pasterBoard = [UIPasteboard pasteboardWithName:@"com.test.image" create:NO];
50. self.bottomImgView.image = pasterBoard.image;
51.  
52. }

 

你可能感兴趣的:(UIMenuController)