简体   繁体   English

捕获复制/粘贴事件UIMenuController

[英]catch the copy/ paste event UIMenuController

Is there any way to catch the copy/paste event in UIMenuController? 有什么办法可以捕获UIMenuController中的复制/粘贴事件吗? I want to set flags when user tap copy option in menu on UIMenuController. 我想在用户点击UIMenuController菜单上的复制选项时设置标志。

Thanks in advance! 提前致谢!

In order to catch the copy/paste event you have to subclass each UI component where you'd like to catch it. 为了捕获复制/粘贴事件,您必须将要捕获它的每个UI组件都子类化。

Simple example with UILabel is shown in Make UILabel Copyable in Swift post. 在Swift帖子中将UILabel复制为可显示UILabel的简单示例。 If you use their final code, don't forget to assign SRCopyableLabel as a base class for UILabel in storyboard. 如果使用他们的最终代码,请不要忘记在情节提要中将SRCopyableLabel分配为UILabel的基类。 Also, modify the required init method in SRCopyableLabel class like that: 同样,修改SRCopyableLabel类中所需的init方法,如下所示:

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    sharedInit()
}

Then, whenever a user taps on "Copy", for instance, the corresponding "copy" method from SRCopyableLabel is called and you can do whatever you want in there: 然后,例如,每当用户点击“复制”时,就会调用SRCopyableLabel的相应“复制”方法,您可以在其中执行任何操作:

override func copy(sender: AnyObject?) {
    let board = UIPasteboard.generalPasteboard()
    board.string = text
    let menu = UIMenuController.sharedMenuController()
    menu.setMenuVisible(false, animated: true)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS在UITableView中创建像popover(UIMenuController)的“复制粘贴” - iOS create “copy paste” like popover (UIMenuController) in UITableView 如何使用UIMenuController iOS5.1防止UITextView上的复制/粘贴/选择弹出框 - How do Prevent a copy/paste/select popover on a UITextView using UIMenuController iOS5.1 从UiMenucontroller隐藏复制选项 - Hide copy option from UiMenucontroller 在UIMenuController中更改默认Copy的标题 - change the title of default Copy in UIMenuController 隐藏UIMenuController显示“粘贴”,“选择”,“全选” - hide UIMenuController displays“ paste”,“select”,“selectAll” 从UIMenuController中删除复制,查找和共享 - Removing Copy, Look Up, and Share from UIMenuController 如何在UITextfield中禁用UIMenuController的复制和定义UIMenuItems - How to disable Copy & Define UIMenuItems of UIMenuController in UITextfield 在显示附加到inputAccessoryView的UIMenuController中隐藏'select','selectAll','paste'? - Hiding 'select', 'selectAll', 'paste' in a UIMenuController displayed attached to a inputAccessoryView? Custom UIMenuController using button event error 只能有一个 UIMenuController 实例 - Custom UIMenuController using button event error There can only be one UIMenuController instance 使用标准的复制并通过自定义UIMenuController项从UIPasteboard检索值 - Use standard Copy and retrieve value from the UIPasteboard with a custom UIMenuController item
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM