在粘貼內容之前,Swift有沒有辦法獲取粘貼的內容?理想情況下,當用戶從可編輯元素的默認彈出式菜單中選擇「粘貼」時,我應該讀取要粘貼的內容。現在我正在查看帶有內容可編輯div的UIWebView。在UIWebView中攔截粘貼操作(Swift)
代碼我迄今(由朱利的回答啓發)
class myWebView: UIWebView {
override public func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
print(action)
return super.canPerformAction(action, withSender: sender)
}
}
輸出(我每次在內容編輯DIV挖掘時間):
切: 副本: 選擇: 全選: 刪除: _promptForReplace: _transliterateChinese: _showTextStyleOptions: _lookup: _define: _addShortcut: _accessibilitySpeak: _accessibilitySpeakLanguageSelection: _accessibilityPauseSpeaking: _share: makeTextWritingDirectionRightToLeft: makeTextWritingDirectionLeftToRight:
Eventhough粘貼選擇沒有列在這裏它,在彈出的菜單中。
我想你可以只讀取並顯示在用戶做任何事情之前,有些類似於瀏覽器的應用程序,不知道攔截行動,也許攔截出現textfield文本是更好的主意 – Tj3n
你的意思是粘貼內容在'UITextField'或'UITextView'? – KrishnaCA