1

when having a menu picker in a VStack and applying the .ignoresSafeArea(.keyboard) modifier the picker "button" gets pushed up by the keyboard. Sometimes its not pushed but it doesn't seem deterministic.

Video: https://i.stack.imgur.com/w3uEl.jpg

import SwiftUI

struct ContentView: View {
    @State var text = ""
    @State var selection = ""
    let foo = ["a","b","c"]
    var body: some View {
        VStack{
            TextField("test", text: $text)
            Spacer()
            HStack{
                Text("test")
                Menu(content:{
                    Picker(selection: $selection, label:
                        EmptyView()
                    , content: {
                        ForEach(foo,id:\.self){f in
                            Label(f, systemImage: "house")
                                .tag(f)
                        }
                    })
                    Picker(selection: $selection, label:
                        EmptyView()
                    , content: {
                        Label("test", systemImage: "plus.circle.fill")
                            .tag("test 1")
                    })
                },label:{
                    Text("test")
                })
            }
        }
        .ignoresSafeArea(.keyboard)

    }
}

An other example (with the suggested Geometry Reader)

Video: https://i.stack.imgur.com/gFFjU.jpg

import SwiftUI

    struct ContentView: View {
    @State var text = ""
    @State var selection = ""
    let foo = ["a","b","c"]
    @FocusState var focus
    var body: some View{
        GeometryReader{_ in
            ZStack{
                Color(UIColor.systemGray6)
                ScrollView{
                    VStack{
                        TextField("title", text: $text)
                            .focused($focus)
                            .frame(maxWidth: .infinity, maxHeight: .infinity)
                            .border(.orange)
                        Spacer()
                    }
                    .frame(maxWidth: .infinity, maxHeight: .infinity)
                }
                overlayInZStack

            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        }
        .ignoresSafeArea(.keyboard, edges: .bottom)
    }
    var overlayInZStack: some View {
        VStack{
            Spacer()
            HStack{
                Button("focus"){
                    focus = true
                }
                Menu(content:{
                    Picker(selection: $selection, label:
                        EmptyView()
                    , content: {
                        ForEach(foo,id:\.self){f in
                            Label(f, systemImage: "house")
                                .tag(f)
                        }
                    })
                    Picker(selection: $selection, label:
                        EmptyView()
                    , content: {
                        Label("test", systemImage: "plus.circle.fill")
                            .tag("test 1")
                    })
                },label:{
                    Image(systemName: "house")
                        .padding(10)
                        .background(Circle().foregroundColor(.red))
                        .border(Color.red)
                })
                .border(Color.orange)
            }
            .border(Color.green)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .border(Color.black)
        
    }
}
sheldor
  • 115
  • 12
  • Unfortunately embed it in `ZStack` with `Color.clear` at background didnt solve it – sheldor Sep 15 '22 at 17:54
  • Check this one https://stackoverflow.com/a/64016326/6433023, with `GeometryReader` I have tested and its works – Nirav D Sep 15 '22 at 18:34
  • @NiravD thanks. I updated the question with an other example where I tried it, where it not worked. I think this example is nearer at my real problem. I would appreciate it if you could look at this example. – sheldor Sep 16 '22 at 18:50
  • I have tried changing many things in your code but still pushed the menu button a little bit. Can you add the reason why you are adding `ZStack` and `ScrollView`. – Nirav D Sep 21 '22 at 04:34
  • I would like to have a tool row overlay over the Scrollview at the bottom. One part is the selection with the menu picker. Perhaps I should rearrange the view – sheldor Sep 21 '22 at 13:37

0 Answers0