2013-10-23 24 views
0

如何將MKMapView的UIImage與覆蓋MKPolylines?我嘗試了renderInContext和MKMapSnapshotter,但沒有在生成的圖像中包含地圖及其疊加層。 renderInContext在iOS 7中根本不起作用。帶有覆蓋的MKMapView到UIImage

回答

2

根據documentation for the MKMapSnapshotter class,生成的快照中不包含疊加和註釋。根據documentation for the MKMapSnapshot class,您可以使用pointForCoordinate自行在快照圖像上手動繪製疊加層和註釋。

另外,您可能需要發佈renderInContext代碼。

- 編輯 -

在iOS系統7,他們增加了以下三個新方法,你可能想嘗試沿着renderInContext方法:

– snapshotViewAfterScreenUpdates: // Captures view as a snapshot view, which may allow you to draw an image using renderInContet. 
– resizableSnapshotViewFromRect:afterScreenUpdates:withCapInsets: // Similar to the previous method, except using a rect. 
– drawViewHierarchyInRect:afterScreenUpdates: // Draws the entire view hierarchy, so this may allow you to capture subviews. 
+0

我的問題是有沒有其他的辦法除了這兩種方法之外。 – smartfuse

+0

@smartfuse查看我編輯的答案。另外,請發佈您的renderInContext方法代碼。我在iOS 7中使用它(儘管沒有地圖視圖),它對我來說工作正常。 – Kamaros

+0

我決定在UIImage中手動繪製線條。不過謝謝。 – smartfuse