Swift中有没有办法在粘贴之前获取粘贴的内容?理想情况下,当用户从可编辑元素的默认弹出菜单中选择“粘贴”时,我应该读取要粘贴的内容。现在我正在查看一个带有内容可编辑 div 的 UIWebView。
到目前为止我的代码(受到 Ludovic 的回答的启发)
class myWebView: UIWebView {
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
print(action)
return super.canPerformAction(action, withSender: sender)
}
}
输出(每次点击内容可编辑 div 时):
剪切: 复制: 选择: 全选: 删除: _提示替换: _音译中文: _showTextStyle选项: _抬头: _定义: _添加快捷方式: _accessibility说: _accessibilitySpeakLanguageSelection: _accessibilityPauseSpeaking: _分享: makeTextWritingDirectionRightToLeft: makeTextWritingDirectionLeftToRight:
尽管此处未列出粘贴选择器,但它可以在弹出菜单中使用。
最佳答案
您可以在粘贴之前获取粘贴的内容
let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
print("String is \(theString)")
}
关于ios - 在 UIWebView 中拦截粘贴操作 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42342991/