I could implement everything using - (BOOL)becomeFirstResponder
as a hook to display the popover and observing the first responder to automatically hide the popover:
- (void)viewDidMoveToWindow
{
[super viewDidMoveToWindow];
[self.window addObserver:self forKeyPath:NSStringFromSelector(@selector(firstResponder)) options:0 context:NULL];
}
As a start point, I published a working project with the classes on GitHub (MIT License):