停止打印NSView [英] Stop NSView from printing
问题描述
我在Xcode中有一个非常基本的Mac应用程序,带有拆分视图,该拆分视图包含PDFThumbnailView和PDFView.(就像预览一样.)
I have a very basic Mac application in Xcode with a Split View that contains a PDFThumbnailView and a PDFView. (Just like Preview.)
除了将PDF加载到视图中所需的代码之外,几乎没有任何Swift代码.
There's hardly any Swift code beyond what is required to load a PDF into the views.
但是,当我从打印"菜单中选择打印"时,除非我先单击PDFView,否则该应用程序要打印ThumbnailView.
However, when I select Print from the Print menu, the app wants to print the ThumbnailView, unless I click on the PDFView first.
有什么办法可以使它始终打印PDFView而不打印ThumbnailView?我认为这是情节提要中某个地方的设置或参数,而不是这样的一些代码.
Is there any way to always make it print the PDFView and never the ThumbnailView? I presume it's a setting or parameter somewhere in the Storyboard, rather than a bit of code as such.
Mojhave 10.14.5上的Xcode 10.2.1.
Xcode 10.2.1 on Mojhave 10.14.5.
推荐答案
一个简单的解决方案是在控制器上以及在XIB文件更改中提供您自己的打印方法(例如 printContent:
)打印菜单项的目标方法改为 printContent:
而不是 print:
An easy solution would be to provide your own print method (like printContent:
) on your controller, and in your XIB file change the target method for the print menu item to printContent:
instead of print:
// eg.
@IBOutlet weak var pdfThumbnails: PDFThumbnailView!
@IBOutlet weak var pdfContent: PDFView!
...
@IBAction func printContent(_ sender: Any) {
self.pdfContent.printView(sender)
}
这篇关于停止打印NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!