How to hide keyboard
using SwiftUI
for below cases?
Case 1
I have TextField
and I need to hide the keyboard
when the user clicks the return
button.
Case 2
I have TextField
and I need to hide the keyboard
when the user taps outside.
How I can do this using SwiftUI
?
Note:
I have not asked a question regarding UITextField
. I want to do it by using SwifUI
(TextField
).
I found another way to dismiss the keyboard that doesn't require accessing the
keyWindow
property; as a matter of fact the compiler gives back a warning usingInstead I used this code: