zoukankan      html  css  js  c++  java
  • UIPasteboard粘贴板:UIMenuController自定义(三)

    这篇咱总结总结自定义剪贴板的使用

    其实自定义剪贴板也非常简单,无非是放开响应时间,通过UIMenuController自定义剪贴板,然后就是最关键的实现你所用的copy方法拉。

    为了方便实用,我给cell添加了长按事件,看代码---

    UILongPressGestureRecognizer *recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];

        [cell addGestureRecognizer:recognizer];

    好,事件加上了,剩下的点击就是实现自定义剪贴板了,上代码:

     

    - (void)longPress:(UILongPressGestureRecognizer *)recognizer{

           if (recognizer.state == UIGestureRecognizerStateBegan) {

                 CopyCell *cell = (CopyCell *)recognizer.view;

                 [cell becomeFirstResponder];

                UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"Flag"action:@selector(flag:)];

                UIMenuItem *approve = [[UIMenuItem alloc] initWithTitle:@"Approve"action:@selector(approve:)];

                UIMenuItem *deny = [[UIMenuItem alloc] initWithTitle:@"Deny"action:@selector(deny:)];

                UIMenuController *menu = [UIMenuController sharedMenuController];


            [menu setMenuItems:[NSArray arrayWithObjects:flag, approve, deny, nil]];


            NSLog(@".....%@",NSStringFromCGRect(cell.frame));

            [menu setTargetRect:cell.frame inView:cell.superview];


            [menu setMenuVisible:YES animated:YES];

          }

    }

    通过上面这段代码,自定义剪贴板成功搞定,运行,你猛然会发现,操,怎么剪贴板没有出来,我猜你已经想到为什么了,因为

    - (BOOL)canBecomeFirstResponder{

        return YES;

    }

    这么重要的一句话没有加,OK,下面就是你所要使用的方法了

    - (void)flag:(id)sender {


        NSLog(@"Cell was flagged");


    }

    - (void)approve:(id)sender {


        NSLog(@"Cell was approved");

    }


    - (void)deny:(id)sender {


        NSLog(@"Cell was denied");


    }

  • 相关阅读:
    QT小技巧
    C#通用类库设置开机自运行禁用任务管理器注册表等操作
    C#通用类库农历类(很全面)
    C#通用类库导出数据(比其他方式快200倍)
    如果你想当程序员!请看!
    C#通用类库汉字转拼音
    C#通用类库加密解密类
    C#制作图片压缩工具
    QT编写图片数据转换工具
    C++面试题 virtual
  • 原文地址:https://www.cnblogs.com/niexiaobo/p/4465099.html
Copyright © 2011-2022 走看看