swift 键盘解雇

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了swift 键盘解雇相关的知识,希望对你有一定的参考价值。


1. KeyboardDismisser:- is a little Swift 4.x pod that adds a button over keyboard so that users can dismiss keyboard easily.
   Source: https://cocoapods.org/pods/KeyboardDismisser
   
2. IQKeyboardManager:- good solution
   Source: https://cocoapods.org/pods/IQKeyboardManagerSwift
// Source: https://stackoverflow.com/questions/24126678/close-ios-keyboard-by-touching-anywhere-using-swift

// 1. 
override func viewDidLoad() {
        super.viewDidLoad()
        
        //Looks for single or multiple taps.
        let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action:  #selector(dismissKeyboard))
        
        //Uncomment the line below if you want the tap not not interfere and cancel other interactions.
        //tap.cancelsTouchesInView = false
        self.view.addGestureRecognizer(tap)
    }
    
//Calls this function when the tap is recognized.
@objc func dismissKeyboard() {
    //Causes the view (or one of its embedded text fields) to resign the first responder status.
    self.view.endEditing(true)
}

// 2. Above website contains easy method of creating an extension of textfield for multiple view controllers
// https://stackoverflow.com/questions/24126678/close-ios-keyboard-by-touching-anywhere-using-swift

以上是关于swift 键盘解雇的主要内容,如果未能解决你的问题,请参考以下文章

有没有办法防止键盘被解雇?

Swift - 解雇后的popViewController

Swift:在解雇的完成处理程序中呈现 VC

解雇 UIKeyboard 在 Objective-C 中不起作用

iOS Swift:如何创建像 UIAlertView 这样看似在解雇后自行消失的对象

如果用户解雇或忽略第一个通知,如何重复本地通知?