Can you change whether a UIButton has a UIMenu or not depending on external conditions?
let infoButton = UIButton()
infoButton.showsMenuAsPrimaryAction = true
infoButton.menu = UIMenu(options: .displayInline, children: [])
infoButton.addAction(UIAction { [weak infoButton] (action) in
infoButton?.menu = infoButton?.menu?.replacingChildren([new items go here...])
}, for: .menuActionTriggered)
Is there a way to block that menu, but trigger a TouchUpInside type of a control event on certain conditions?
If you didn’t want the menu to appear when the button is tapped, you should not have set
showsMenuAsPrimaryActiontotrue. That value means that the touch up inside target-action, if there is one, is ignored and the menu appears instead.