问题
I would like to make a Popover that can show as a popover like the spotlight search implementation? I can only use traditional way to show a Quicklook window on the centre, but I would like to make something like this:
How can I do so? Thanks.
回答1:
This can be achieved by creating a QLPreviewView instance embedded within a NSPopover.
Then, create a NSObject subclass that conforms to the QLPreviewItem protocol and set the previewItem
property on your QLPreviewView
like when working with the traditional QuickLook QLPreviewPanel
.
QLPreviewView *view = [[QLPreviewView alloc] initWithFrame:NSMakeRect(0, 0, 800, 100) style:QLPreviewViewStyleNormal];
JPQuickLookItem *item = [[JPQuickLookItem alloc] init];
item.previewItemURL = [NSURL fileURLWithPath:@"/Users/josh/Desktop/Test.png"];
item.previewItemTitle = @"Test.png";
view.previewItem = item;
I've created a sample Swift implementation here.
来源:https://stackoverflow.com/questions/23959375/how-to-put-the-qlpreviewpanel-show-as-a-popover-in-cocoa