“cara mengabaikan keyboard di Swift” 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 “cara mengabaikan keyboard di Swift”

Pertanyaan yang mirip dengan “cara mengabaikan keyboard di Swift”

Lebih banyak jawaban terkait untuk “cara mengabaikan keyboard di Swift” di Swift

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya