zoukankan      html  css  js  c++  java
  • 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删除掉。则依旧能够进粘贴行。



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

  • 相关阅读:
    编写登陆认证程序
    Ubuntu18.04安装MySQL
    python输出的高亮显示
    河北省赛
    dp
    迷宫问题
    牛客-幸运数字Ⅱ
    [管理运筹学]线性规划&单纯形法的各种姿势(题目:[NOI2008]志愿者招募)
    [管理运筹学]指派问题的匈牙利算法及其c++实现 (例:「网络流 24 题」分配问题 )
    打算在CSDN写了,虽然博客园也很好
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4718385.html
Copyright © 2011-2022 走看看