I'm using this pod in order to work on text fields and keyboard. In my App.Delegate file, I imported IQKeyboardManagerSwift and enabled it, which works fine now. However, the problem I have now is even when the user tap return key on the keyboard, I cannot dismiss the keyboard and the keyboard remains the same. I added IQKeyboardManager.shared.shouldResignOnTouchOutside = true
, so when the user taps the outside of the keyboard, the keyboard dismisses. I want to add the functionality that when the user tap return button on the keyboard, the keyboard also dismisses. I guess resignFirstResponder()
will enable this function (Resigns currently first responder field), but I don't know how to implement that function.
I saw some other people use textfieldShouldReturn function, but I think I have to make the function several times if I add code in the view controllers. Currently, I have several text fields, so if possible, I just want to write code only one time.
How can I implement that function?
import IQKeyboardManagerSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
IQKeyboardManager.shared.enable = true
IQKeyboardManager.shared.enableAutoToolbar = false
IQKeyboardManager.shared.shouldResignOnTouchOutside = true
IQKeyboardManager.shared.resignFirstResponder()
return true
}
....
}