4

I have a UIButton with a UIMenu attached, I need to know when the UIMenu is dismissed (by tapping outside the UIMenu) so I can remove the button that the UIMenu is attached to.

I have seen there are notifications for UIMenuController, but that is different.

edit: Here's some additional info because this question was related to a different question.

I don't care when the UIMenu is called, I only care when it is dismissed

Ungrace
  • 214
  • 2
  • 12
  • I understand your objection and I've reopened, but it's still really the same issue as https://stackoverflow.com/questions/69710316/get-an-event-when-uibarbuttonitem-menu-is-displayed (in another guise). – matt Dec 16 '21 at 15:16
  • 2
    I had considered that, so I tried the implementation on that issue, but uideferredelement menu.uncached is only calling when the menu appears. not when its dismissed. But maybe im implementing it wrong. – Ungrace Dec 16 '21 at 15:51
  • I do not say the answer answers your question. I'm saying it's effectively the same _question,_ namely where are the signals when the menu appears / disappears? – matt Dec 16 '21 at 17:28

1 Answers1

1

You have to create custom button (for call menu) and override its method contextMenuInteraction(_:willEndFor:animator:). Add your action inside this method for removing the button that the UIMenu is attached to.

zslavman
  • 401
  • 5
  • 11