xcode – 如何在MKMapView Swift中放大图钉

前端之家收集整理的这篇文章主要介绍了xcode – 如何在MKMapView Swift中放大图钉前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望引脚的位置在敲击引脚时放大,以便位置位于中心.我不知道该怎么做.请帮我.

解决方法

你想要做的事情有很多.

>确定敲击了哪个引脚
>将mapView置于攻丝针上

如果您在项目中正确启动了mapView(以视图作为其委托),则可以使用mapView(_:didSelectAnnotationView:)方法完成上述两点,如下所示:

func mapView(mapView: MKMapView,didSelectAnnotationView view: MKAnnotationView) {

        // get the particular pin that was tapped
        let pinToZoomOn = view.annotation

        // optionally you can set your own boundaries of the zoom
        let span = MKCoordinateSpanMake(0.5,0.5)

        // or use the current map zoom and just center the map
        // let span = mapView.region.span

        // now move the map
        let region = MKCoordinateRegion(center: pinToZoomOn!.coordinate,span: span)
        mapView.setRegion(region,animated: true)
}

方法告诉委托(您的视图最有可能)选择了一个地图注释视图并移动(和/或缩放)到该坐标区域.

猜你在找的Xcode相关文章