问题描述
我有一个带有MKMapView的iOS应用。我使用the standard UIPrintInteractionController允许用户打印地图或将其另存为PDF。
但是有两个问题:
我希望能够以更高的分辨率打印地图,因为打印表面允许这样做,这将是用户打印地图的强烈理由,而且我也希望地图能在页面中占主导地位(填充它。)
我尝试从打印格式化程序中提取rect,但这不起作用。格式化程序似乎是地图的“快照”。我想我可以简单地临时更改地图视图框架,以具有US Letter页面的矩形和外观,但是,那么我将固定在一种页面格式上。
我也尝试过在格式化程序中创建一个临时的mapview,但这只是给我一个空白页面。
对此,我将不胜感激。我不在这方面做过很多编码。
更新:我不能随意透露正在开发的应用程序的完整代码库,但这是我为地图使用的处理程序:
@IBAction func barButtonActionItemHit(_: Any) {
if let mapView = mapView {
let sharedPrintController = UIPrintInteractionController.shared
let printInfo = uiprintinfo(dictionary: nil)
printInfo.outputType = uiprintinfo.OutputType.general
printInfo.jobName = "print Job"
mapView.overrideUserInterfaceStyle = .light // Forces the map to render as light.
sharedPrintController.printPageRenderer = Rcvrr_LocationPagePrintRenderer(withMap: mapView.viewPrintFormatter())
sharedPrintController.present(from: self.view.frame,in: self.view,animated: false) { [weak self] (_,_,_) in self?.mapView.overrideUserInterfaceStyle = .unspecified }
}
}
这是渲染器(UIPrintPageRenderer子类)中的例程:
override func drawContentForPage(at inPageIndex: Int,in inContentRect: CGRect) {
self.mapformatter?.draw(in: inContentRect,forPageAt: 1)
}
这是我尝试过的方法,但是无效(空白页):
override func drawContentForPage(at inPageIndex: Int,in inContentRect: CGRect) {
dispatchQueue.main.async { [weak self] in
if let region = self?.mapView?.region {
let tempMapView = MKMapView(frame: inContentRect)
tempMapView.region = region
self?.mapView?.annotations.forEach {
tempMapView.addAnnotation($0)
}
tempMapView.viewPrintFormatter().draw(in: inContentRect,forPageAt: 1)
}
}
}
我并不感到惊讶。我在格式化程序中创建了一个格式化程序,但是我不知道如何获取目标矩形。
更新2:以下是其外观的一些屏幕截图:
首先,这是显示屏:
如果我们放大,会发现细节水平很差:
这就是我想要看到的:
谢谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)