Why is my menu open upwards when I want it to open downwards in Swift 13.4?

How can I fix it (Swift 13.4!)?

Code:

struct ContentView: View {
    var body: some View {
        Menu("Options") {
            Button("1", action: func1)
            Button("2", action: func2)
            Button("Cancel", action: cancel)
         }
    }
    func func1() { }
    func func2() { }
    func cancel() {
    }
}

Answered by Claude31 in 749407022

Position of popup is automatically computed, depending on space available.

If you add a Spacer(), you will see menu options show below, and in the reverse order (nice).

struct ContentView: View { var body: some View { Menu("Options") { Button("1", action: func1) Button("2", action: func2) Button("Cancel", action: cancel) } Spacer() } }

Hence a solution: create a MenuView and force Menu at top with a Spacer

struct MenuView: View {
    var body: some View {
        Menu("Options") {
            Button("1", action: func1)
            Button("2", action: func2)
            Button("Cancel", action: cancel)
        }
        Spacer()
    }
    func func1() { }
    func func2() { }
    func cancel() { }
}

struct ContentView: View {
    var body: some View {
        MenuView()
            .frame(width: 200, height: 200, alignment: .top)
    }
}

Accepted Answer

Position of popup is automatically computed, depending on space available.

If you add a Spacer(), you will see menu options show below, and in the reverse order (nice).

struct ContentView: View { var body: some View { Menu("Options") { Button("1", action: func1) Button("2", action: func2) Button("Cancel", action: cancel) } Spacer() } }

Hence a solution: create a MenuView and force Menu at top with a Spacer

struct MenuView: View {
    var body: some View {
        Menu("Options") {
            Button("1", action: func1)
            Button("2", action: func2)
            Button("Cancel", action: cancel)
        }
        Spacer()
    }
    func func1() { }
    func func2() { }
    func cancel() { }
}

struct ContentView: View {
    var body: some View {
        MenuView()
            .frame(width: 200, height: 200, alignment: .top)
    }
}

Got it, thanks for your reply.

Why is my menu open upwards when I want it to open downwards in Swift 13.4?
 
 
Q