iOS/SwiftUI
SwiftUI) textfield 작성 후 버튼 클릭시 keyboard dismiss(hide, 숨기기)
behan
2022. 4. 4. 21:39
반응형
#if canImport(UIKit)
extension View {
func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
#endif
생성 후
Button {
locationSearchViewModel.fetchLocationSubject.send(location)
hideKeyboard()
} label: {
Text("Search")
}
버튼 action에 추가하면 keyboard 숨기기 가능
반응형