我有兩個視圖控制器。一個可以讓用戶輸入的東西自己目擊:如何抵消MKMapView把座標放在指定的點
另一種是一個UITableViewController,讓他們看到自己提交的蹤跡:
我想是的用戶能夠在第二個VC中點擊他們的目擊,並且用它填充第一個VC以及相關細節。我有工作使用文本框:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let pvc = self.navigationController?.previousViewController() as! SubmitSightingVC
let sighting = sightingsArray[indexPath.row]
pvc.titleTextField.text = sighting["title"] as! String?
pvc.locationTextField.text = sighting["location"] as! String?
pvc.dateTextField.text = sighting["date"] as! String?
pvc.descriptionTextView.text = sighting["sightingDesc"] as! String?
let pinArray = ["1", "2", "3", "4", "5"]
let pinTextArray = ["1text", "2text", "3text", "4text", "5text"]
var pinImageArray = [#imageLiteral(resourceName: "1"), #imageLiteral(resourceName: "2"), #imageLiteral(resourceName: "3"), #imageLiteral(resourceName: "4"), #imageLiteral(resourceName: "5")]
let pinIconString = sighting["pinIcon"] as! String
let index = pinArray.index(of: pinIconString)
pvc.pinImageView.image = pinImageArray[index!]
pvc.pinTextField.text = pinTextArray[index!]
// Bit I'm struggling with:
var coordinates = CLLocationCoordinate2D(latitude: sighting["latitude"] as! Double, longitude: sighting["longitude"] as! Double)
pvc.mapView.centerCoordinate = coordinates
self.navigationController!.popViewController(animated: true)
}
的問題是,因爲地圖的中心是模糊的觀點背後偏移。地圖上的引腳不是實際的引腳,而是UIImage(pinImageView)。我如何移動地圖,以便座標位於pinImage下方而不是位於mapView的中心?
查看'MKMapCamera'您可以使用它來偏移地圖,以您想要的爲中心。文檔:https://developer.apple.com/reference/mapkit/mkmapcamera – rmp