我有一個UITableView,每個單元格都應該顯示一個地圖。由於在一個視圖中有幾個獨立的SKMapView實例(見http://developer.skobbler.com/getting-started/ios#sec29),並且我不希望每個單元格中都有SKMapView(性能),所以我認爲我會使用renderMapImageInBoundingBox並創建要顯示的地圖圖像在表格中。rendermapImageInBoundingBox在iOS上不執行任何操作
我已經嘗試了幾件事,並剝離了代碼來爲第一張地圖渲染圖像。這是我在我的UITableViewController的viewDidAppear(我也試過viewDidLoad,但沒有)的一個剝離版本。
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(true)
//Initialize, set delegate, and customize map appearance
var mapView = SKMapView(frame: CGRectMake(0, 0, 963, 200))
mapView.delegate = self
mapView.applySettingsFromFileAtPath(JSONFilePath)
mapView.mapScaleView.hidden = true
mapView.settings.showAccuracyCircle = false
mapView.settings.panningEnabled = false
mapView.settings.rotationEnabled = false
mapView.settings.showStreetBadges = false
mapView.settings.showHouseNumbers = false
mapView.settings.showMapPoiIcons = false
mapView.settings.showOneWays = false
//Draw a track on the map
let track = tracks[0]
var polyline = SKPolyline()
polyline.coordinates = track.points
polyline.fillColor = themeTintColor
polyline.lineWidth = 3
polyline.backgroundLineWidth = 4
polyline.borderDotsSize = 1
polyline.borderDotsSpacingSize = 5
mapView.addPolyline(polyline)
//Set BoundingBox
let boundingBox = SKBoundingBox(topLeftCoordinate: CLLocationCoordinate2DMake(track.ne.coordinate.latitude, track.sw.coordinate.longitude), bottomRightCoordinate: CLLocationCoordinate2DMake(track.sw.coordinate.latitude, track.ne.coordinate.longitude))
// Add the mapView to the view just to see if it displays correctly. (It does!)
mapView.fitBounds(boundingBox, withPadding: CGSizeMake(20, 20))
self.view.addSubview(mapView)
// Actual PNG rendering
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
mapView.renderMapImageInBoundingBox(boundingBox, toPath: documentsPath, withSize: CGSizeMake(1000, 220))
println("Rendering in progress")
}
func mapViewDidFinishRenderingImageInBoundingBox(mapView: SKMapView!) {
println("ImageRenderingFinished")
}
的MapView正確顯示(使用正確的邊框),並在日誌中我看到「渲染正在進行中」的消息,但mapViewDidFinishRenderingImageInBoundingBox不會被調用,我沒有看到在創建png文件我應用容器。沒有編譯器或運行時錯誤。 (順便說一句,我沒有忘記添加SKMapViewDelegate)
任何人有一個想法我做錯了什麼?還是我碰到一個bug? 使用Xcode 6.1,在Swift中爲iOS8開發。