iOS 11无法禁用复制粘贴选项UITextField

时间:2017-10-09 11:54:47

标签: ios swift cocoa-touch uitextfield ios11

我正在使用Xcode 9和iOS 11,谷歌搜索禁用复制粘贴选项,但没有成功。

enter image description here

低于我的尝试:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    if action == #selector(UIResponderStandardEditActions.paste(_:)) || action == #selector(UIResponderStandardEditActions.copy(_:)) {
        return false
    }

    return true
}

还尝试过:

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        if action == #selector(UIResponderStandardEditActions.paste(_:)) || action == #selector(paste(_:)) || action == #selector(cut(_:)) || action == #selector(selectAll(_:)) || action == #selector(select(_:)){
            return false
        }

        return true
    }

并尝试了Stackoverflow的许多其他代码。但没有成功。实际上我不想显示上面的菜单,然后长按UITextField

2 个答案:

答案 0 :(得分:1)

经过测试并在iOS 12中正常工作

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/appscript/reference.py", line 482, in __call__
    return self.AS_appdata.target().event(self._code, params, atts, codecs=self.AS_appdata).send(timeout, sendflags)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/aem/aemsend.py", line 92, in send
    raise EventError(errornum, errormsg, eventresult)
aem.aemsend.EventError: Command failed: Parameter error. (-50)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/matthewbell/Desktop/test.py", line 4, in <module>
    b.save('test_book2.xlsm')
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlwings/main.py", line 704, in save
    return self.impl.save(path)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/xlwings/_xlmac.py", line 244, in save
    self.xl.save_workbook_as(filename=hfs_path, overwrite=True)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/aeosa/appscript/reference.py", line 518, in __call__
    raise CommandError(self, (args, kargs), e, self.AS_appdata) from e
appscript.reference.CommandError: Command failed:
        OSERROR: -50
        MESSAGE: Parameter error.
        COMMAND: app(pid=6198).workbooks['Book1'].save_workbook_as(filename='Macintosh HD:Users:matthewbell:Desktop:test_book2.xlsm', overwrite=True)

答案 1 :(得分:0)

以下5条代码对我有用

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    OperationQueue.main.addOperation {
        UIMenuController.shared.setMenuVisible(false, animated: false)
    }
    return super.canPerformAction(action, withSender: sender)
}