“Swift memberhentikan keyboard saat kembali” Kode Jawaban

cara mengabaikan keyboard swiftui

#if canImport(UIKit)
extension View {
    func hideKeyboard() {
        UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
#endif
Quaint Quail

cara mengabaikan keyboard di Swift

override func viewDidLoad() {
    super.viewDidLoad()

    //Looks for single or multiple taps. 
    let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "dismissKeyboard")

    //Uncomment the line below if you want the tap not not interfere and cancel other interactions.
    //tap.cancelsTouchesInView = false 

    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.
    view.endEditing(true)
}
Encouraging Eland

Swift memberhentikan keyboard saat kembali

extension UIViewController: UITextFieldDelegate{
    public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true;
    }
}

override func viewDidLoad() {
    super.viewDidLoad()
    textField.delegate = self
}
Mobile Star

Jawaban yang mirip dengan “Swift memberhentikan keyboard saat kembali”

Pertanyaan yang mirip dengan “Swift memberhentikan keyboard saat kembali”

Lebih banyak jawaban terkait untuk “Swift memberhentikan keyboard saat kembali” di Swift

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya