onaperate, ошибку, Tap -Gesture, SimultAneus Gesture
Import swiftui < /p>
Код: Выделить всё
struct ContentView: View {
@State private var text: String = ""
var body: some View {
NavigationView {
VStack {
TextField("Escribe algo...", text: $text)
.textFieldStyle(RoundedBorderTextFieldStyle())
.padding()
Menu {
Button("Perfil", action: menuTapped)
Button("Configuración", action: menuTapped)
Button(role: .destructive, action: menuTapped) {
Label("Cerrar sesión", systemImage: "power")
}
} label: {
Label("Menú", systemImage: "line.3.horizontal")
.font(.title)
.padding()
}
.onTapGesture {
hideKeyboard()
}
}
.navigationTitle("Inicio")
}
}
// Acción al tocar el menú
private func menuTapped() {
hideKeyboard()
print("Opción seleccionada")
}
// Método para ocultar el teclado
private func hideKeyboard() {
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -menu-item
Мобильная версия