How to put the QLPreviewPanel show as a popover in cocoa?

给你一囗甜甜゛ 提交于 2019-12-10 11:18:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!