想看看是否有办法在屏幕截图后显示警报 View ,然后要求输入与特定字符串匹配的文本。如果用户没有输入正确的文本,则不会关闭警报 View 并提示用户重试。如果用户输入了正确的文本,警报 View 将被关闭。
最佳答案
你可以用这个
let requireTextInput = "require text input"
// add observer for screen shot
NotificationCenter.default.addObserver(forName: NSNotification.Name.UIApplicationUserDidTakeScreenshot, object: nil, queue: OperationQueue.main, using:
{ notification in
var inputTextField = UITextField()
let textPrompt = UIAlertController(title: nil, message: "require text input", preferredStyle: .alert)
textPrompt.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
textPrompt.addAction(UIAlertAction(title: "OK", style: .default, handler: {
(action) -> Void in
// if the input match the required text
let str = inputTextField.text
if str == requireTextInput {
print("right")
} else {
print("wrong")
}
}))
textPrompt.addTextField(configurationHandler: {(textField: UITextField!) in
textField.placeholder = "place Holder"
inputTextField = textField
})
self.present(textPrompt, animated: true, completion: nil)
})
关于ios - 截取屏幕时显示警报并要求输入文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41325820/