将MKMapview复制到NSPasteboard时丢失叠加层

时间:2018-09-20 17:52:05

标签: swift mkmapview nspasteboard

当我尝试复制MKMapView时,例如以轨道作为叠加层时,仅复制地图图像。这是我当前使用的代码

let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.declareTypes([NSPasteboard.PasteboardType.png], owner: self)
let rect = mapView.visibleRect

let rep = mapView.bitmapImageRepForCachingDisplay(in: rect)
mapView.cacheDisplay(in: rect, to: rep!)
pasteboard.setData(rep?.representation(using: 
NSBitmapImageRep.FileType.png, properties: [:]), forType: 
NSPasteboard.PasteboardType.png)

预期结果:具有所有叠加层的Mapview图像 实际结果:仅地图

我还尝试了writePDFinsdeRect,但随后仅将图例复制到NSPasteboard。

我想我在这里错过了一些东西。

0 个答案:

没有答案
相关问题