我有两个视图控制器。 一个允许用户输入他们自己的事物:
另一个是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的中心?
I have two view controllers. One allows the user to enter their own sightings of things:
The other is a UITableViewController that allows them to see their submitted sightings:
What I want is for the user to be able to click on their sighting in the 2nd VC and for it to populate the 1st VC with the relevant details. I have that working for the textFields using :
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) }The problem is that because the centre of the map is behind the blurred view it is offset. The pin on the map isn't an actual pin but a UIImage (pinImageView). How can I move the map so that the coordinates are under this pinImage instead of in the centre of the mapView?
最满意答案
如上所述,您可以使用MKMapCamera定位地图视图,也可以使用setVisibleMapRect并添加一些填充来定位地图,如下所示:
self.mapView.setVisibleMapRect(self.mapView.visibleMapRect, edgePadding: UIEdgeInsetsMake(200.0, 0.0, 0.0, 0.0), animated: true)这将使顶部的中心偏移200个屏幕像素。
As mentioned above you can use the MKMapCamera to position the view of the map or you can also use setVisibleMapRect and add some padding to position the map like this:
self.mapView.setVisibleMapRect(self.mapView.visibleMapRect, edgePadding: UIEdgeInsetsMake(200.0, 0.0, 0.0, 0.0), animated: true)This will offset the center by 200 screen pixels on the top.
更多推荐
发布评论