Dismiss Keyboard SwitUI

Hello
Is there a way to dismiss a decimal Keyboard by tapping (anywhere) on the screen (without putting .onTapGesture {hideKeyboard()} on the NavigationView)
Thank you
Answered by OOPer in 654688022

Is there a way to dismiss a decimal Keyboard by tapping (anywhere) on the screen (without putting .onTapGesture {hideKeyboard()} on the NavigationView)

As far as I know, the answer is NO.
You need to write hideKeyboard() (I assume you know how to implement it) in onTapGesture or in some other action closure.

Hiding keyboard is a frustrating topic even in UIKit. You can send a feature request using Apples Feedback Assistant.
Would this be a solution ?
Code Block
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)

https ://www.hackingwithswift .com/quick-start/swiftui/how-to-dismiss-the-keyboard-for-a-textfield

Or do search to hide as soon as you leave the field ?

In UIKit, I had to add a return button to the pad.
Accepted Answer

Is there a way to dismiss a decimal Keyboard by tapping (anywhere) on the screen (without putting .onTapGesture {hideKeyboard()} on the NavigationView)

As far as I know, the answer is NO.
You need to write hideKeyboard() (I assume you know how to implement it) in onTapGesture or in some other action closure.

Hiding keyboard is a frustrating topic even in UIKit. You can send a feature request using Apples Feedback Assistant.
Dismiss Keyboard SwitUI
 
 
Q