【发布时间】:2018-03-20 15:03:58
【问题描述】:
我正在使用 Xcode 9 和 iOS 11,谷歌搜索禁用复制粘贴选项但没有成功。
低于我的尝试:
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。
【问题讨论】:
-
你需要
override var canBecomeFirstResponder: Bool { return true } -
这个方法会被调用吗?
-
我检查了你的代码,它在 iOS 11 中运行
-
@NikhilManapure - 是的
-
@Rajesh - 你没有看到上面的选择菜单把它作为图像吗?
标签: ios swift cocoa-touch uitextfield ios11