I create a UIKit PullDown menu (in a positionMenu button), with the following code:
func setupPullDownMenu() {
let menu1 = UIAction(title: "Menu1") { [self] _ in
// some code
}
let menu2 = UIAction(title: "Menu2") { [self] _ in
// some code
}
let menu3 = UIAction(title: "Menu3") { [self] _ in
// some code
}
let menu = UIMenu(title: "Positions", children: [menu1, menu2, menu3])
positionMenu.menu = menu
positionMenu.showsMenuAsPrimaryAction = true
}
In Portrait, options are listed as Menu1, Menu2, Menu3
But in Landscape it is the reverse: Menu3, Menu2, Menu1
I use Xcode 16.1ß and iOS 17.0 simulator
Is it the expected behaviour ?
Got the answer https://stackoverflow.com/questions/74372108/how-to-force-the-order-of-uikit-pop-up-menu-button-items
Yes it is the expected behaviour, due to the available screen space vertically, in order to display the first menu element in the UIMenu closest to the location of the user interaction.
To get fixed order (in iOS 16 and later):
positionMenu.preferredMenuElementOrder = .fixed