MGLAnnotationView als Sourceview zu setzen, was ich tun möchte, ist mit der Anmerkung als Quelle Ansicht/Anker einen popover präsentierenWie für popover
Delegatfunktion didSelect AnnotationView Durch die Verwendung sollte ich in der Lage sein, dies zu erreichen, , aber es scheint überhaupt nicht zu laufen. Für jetzt bin ich nur didSelect Anmerkung meine popover über präsentiert und haben die Sourceview auf Navigationsleiste, nur für sie irgendwo zeigt ...
FYI: Ich habe das MapBox SDK in das Projekt umgesetzt . Ich habe keine Probleme, die gleiche Aufgabe mit MapKit durchzuführen.
Hat jemand eine Idee, was ich tun kann, um dies zu erreichen?
Code-Schnipsel unter:
import UIKit
import Mapbox
class ViewController: UIViewController, MGLMapViewDelegate, UIPopoverPresentationControllerDelegate {
@IBOutlet var theMap: MGLMapView!
override func viewDidLoad() {
super.viewDidLoad()
theMap.delegate = self
let point = MGLPointAnnotation()
point.coordinate = CLLocationCoordinate2D(latitude: 55.6, longitude: 13.0)
point.title = "Some place"
point.subtitle = "Malmö, Sweden"
theMap.addAnnotation(point)
}
func mapView(_ mapView: MGLMapView, didSelect annotationView: MGLAnnotationView) {
print("annotation view: ", annotationView)
// this method doesn't seem to get called at all...
// but ideally this is the place to present the popover.
}
func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
print("annotation: ", annotation)
// present the popover
presentPopover()
}
func presentPopover(){
let popover = storyboard?.instantiateViewController(withIdentifier: "MyCalloutVC") as! MyCallout
popover.modalPresentationStyle = UIModalPresentationStyle.popover
popover.popoverPresentationController?.backgroundColor = UIColor.white
popover.popoverPresentationController?.delegate = self
// I would like to set the source anchor to the selected annotation view.
popover.popoverPresentationController?.sourceView = UINavigationBar() // set to nav bar for now...
popover.popoverPresentationController?.permittedArrowDirections = .any
// popover size set in MyCallout
self.present(popover, animated: true)
}
}
Vielen Dank @ppoh71 für Ihre erklärende Antwort, richtige Sachen! Ich bin jetzt auf dem besten Weg. –