Popover from NSToolbarItem in Mac Catalyst app

Hi,

Inside a Mac Catalyst app, I need to display a popover starting from an NSToolbarItem contained inside the app toolbar (like the Apple Maps Mac app does, see below image).

In order to do that, when I press the button I need to find the toolbar item view and use it as popover anchor.

How can I find the view or frame of an NSToolbarItem on Mac Catalyst?

A property that could help me is the NSToolbarItem "view" property (NSView), but that property has been marked has unavailable in Mac Catalyst.

Any idea?

Thank you

Answered by Nik Bhatt in 779659022

Popovers can be applied to Toolbar items on Ventura and later. There is a new API for that - see UIPopoverPresentationController

// Accepts UIBarButtonItem as well as NSToolbarItem in Catalyst.
@available(iOS 16.0, *)
open var sourceItem: UIPopoverPresentationControllerSourceItem?

Did you ever find a solution for this? I'm trying to do the same thing.

Unfortunately not.

What I ended up doing was displaying the popover at specific fixed coordinates to make it look like the origin is the button item in the toolbar. It's not ideal, but it does the job.

Here is the result:

Accepted Answer

Popovers can be applied to Toolbar items on Ventura and later. There is a new API for that - see UIPopoverPresentationController

// Accepts UIBarButtonItem as well as NSToolbarItem in Catalyst.
@available(iOS 16.0, *)
open var sourceItem: UIPopoverPresentationControllerSourceItem?
Popover from NSToolbarItem in Mac Catalyst app
 
 
Q