问题描述
我正在为macOS编写QuickLook插件,并且一切正常,除了无法以编程方式设置预览的窗口大小.
I am writing a QuickLook plugin for macOS and everything works, except that I can't set programmatically the window size of the preview.
无论我在XIB和/或代码中做什么,在调用 preparePreviewOfFile
的 completionHandler
之前和/或之后,它都以800x600开始.
It starts with 800x600, no matter what I do in the XIB and/or in the code, before and/or after the call to the completionHandler
of preparePreviewOfFile
.
其他文件类型(由默认插件处理)使预览窗口的大小适应文件的内容.我只想这样做.
Other file types, handled by the default plugin, adapts the preview window size to the content of the file. I would like to do just that.
预览窗口可以由用户调整大小,并且一旦调整大小,当我在Finder中选择另一个文件时,将保持新的大小,如果我关闭它并在由插件处理的文件上重新打开它,则可以恢复到800x600.
The preview window is resizable by the user and, once resized, keeps the new size when I select another file in the Finder, to go back to 800x600 if I close it and reopen it on a file handled by my plugin.
我想念什么?
推荐答案
QLPreviewingController
应该设置其 preferredContentSize
,以便可以相应地调整窗口的大小.
QLPreviewingController
should set its preferredContentSize
so that the window can be sized accordingly.
https://developer.apple.com/documentation/appkit/nsviewcontroller/1434409-preferredcontentsize
这篇关于使用QLPreviewingController.preparePreviewOfFile进行预览时设置QuickLook窗口大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!