Monday, August 17, 2026
HomeiOS Developmentios - How would you dismiss keyboard inside textual content editor?

ios – How would you dismiss keyboard inside textual content editor?

[ad_1]

I have never discovered any documentation on it. I do know you may dismiss keyboard utilizing .keyboardDismissMode on TabliewView and different UIViews however how would you do this with TextEditor() in SwiftUI? I’ve a swipe gesture characteristic proper now however that does not work when the textual content editor will get lengthy and has to scroll as a result of which it doesnt acknowledge gestures anymore.

code:

VStack{
        TextEditor(textual content: $newNote)
        }
            .gesture(DragGesture(minimumDistance: 20, coordinateSpace: .international)
            .onEnded({ worth in
                if worth.translation.width < 0 {
                    // left
                }
                
                if worth.translation.width > 0 {
                    self.presentationMode.wrappedValue.dismiss()
                    hideKeyboard()
                    self.navigationBarBackButtonHidden = false
                    
                }
                if worth.translation.top < 0 {
                    
                }
                
                if worth.translation.top > 0 {
                    hideKeyboard()
                    self.navigationBarBackButtonHidden = false
                    
                }
            }
                     
                    ))


 extension View {

func hideKeyboard() {
    let resign = #selector(UIResponder.resignFirstResponder)
    UIApplication.shared.sendAction(resign, to: nil, from: nil, for: nil)}
 }

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments