Display MKMapViewAnnotations within a map view's visible rect

后端 未结 7 654
梦毁少年i
梦毁少年i 2021-02-02 02:31

I\'m displaying an MKMapView inside a Path-style parallax table view header. To create the effect, the mapView bounds is larger than the area visible to the user. I need to set

7条回答
  •  长发绾君心
    2021-02-02 03:20

    You first need to add the annotations: (of course this is after you already have a list of annotations)

    Swift4:

        self.mapView.addAnnotations(annotations)
        let currentView = mapView.visibleMapRect
        mapView.annotations(in: currentView)
    

    You can use the currentView constant or directly place the MKMapRect as such: Below: (.visibleMapRect returns:

    "The area currently displayed by the map view."

    mapView.annotations(in: mapView.visibleMapRect)
    

提交回复
热议问题