[英]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.