• UIMenuController,UIPasteboard:复制,粘贴详细解释


    首先,这四个地图。我想实现的功能。【一张照片讲一个复制到另一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删除掉。则依旧能够进粘贴行。



    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    html(单纯html标签)
    python 知识点
    浅谈五大Python Web框架
    Python3的变化
    测试开发
    常见的测试用例设计方法
    数字数据类型及其对应转移字符
    char *p 与char p[]
    C语言运算符优先级 详细列表
    软件自动化测试
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4718385.html
Copyright © 2020-2023  润新知