gpt4 book ai didi

ios - 拦截 UIWebView 中的粘贴操作(Swift)

转载 作者:行者123 更新时间:2023-11-28 08:17:00 24 4
gpt4 key购买 nike

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):

剪切:复制:选择:全选:删除:_promptForReplace:_音译中文:_showTextStyle选项:_抬头:_定义:_添加快捷方式:_accessibilitySpeak:_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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com