I have UIViewController
with UITextfield
and several other elements (several subviews and buttons). I want to close the keyboard when tapped somewhere outside of the UITextfield
.
I know there is an answer Close iOS Keyboard by touching anywhere using Swift, but this way doesn't work if user taps on viewController's subviews or buttons.
I can add the similar UITapGestureRecognizer
for each subViews and buttons, but is there a smarter way to resolve this?