【发布时间】:2017-08-23 05:43:12
【问题描述】:
我有两个视图控制器。一种允许用户输入他们自己对事物的看法:
另一个是 UITableViewController,允许他们查看提交的目击记录:
我想要的是让用户能够点击他们在第二个 VC 中看到的内容,并使用相关详细信息填充第一个 VC。我使用以下方法为 textFields 工作:
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您可以使用它来偏移地图以使地图以您想要的为中心。文档:developer.apple.com/reference/mapkit/mkmapcamera
标签: ios swift mkmapview coordinates