我想通过点击按钮显示可分离的NSPopover,但我卡住了。我遵循教程如何显示NSPopover,但它们都是关于菜单栏应用程序的。
我的AppDelegate看起来像这样
final class AppDelegate: NSObject, NSApplicationDelegate {
var popover: NSPopover!
func applicationDidFinishLaunching(_ notification: Notification) {
let popover = NSPopover()
let popoverView = PopoverView()
popover.contentSize = NSSize(width: 300, height: 200)
popover.contentViewController = NSHostingController(rootView: popoverView)
popover.behavior = .transient
self.popover = popover
}
func togglePopover(_ sender: AnyObject?) {
self.popover.show(relativeTo: (sender?.bounds)!, of: sender as! NSView, preferredEdge: NSRectEdge.minY)
}
}