私は2つのView Controllerを持っています。一つは、ユーザーが物事の独自の目撃情報を入力することができます:MKMapViewをオフセットして、指定したポイントに座標を配置する方法
他は、彼らの提出した目撃情報を見ることができますのUITableViewControllerです:
私が欲しい何のためにありますユーザは第2VCの視力をクリックし、第1VCに関連する詳細を入力することができる。私が使用してテキストフィールドのために働いていることがあります。
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)です。座標がmapViewの中心でなく、このpinImageの下にあるようにマップを移動するにはどうすればよいですか?上述したように
'MKMapCamera'を見てください。あなたが望むものを中心に地図をオフセットするのに使うことができます。 Docs:https://developer.apple.com/reference/mapkit/mkmapcamera – rmp