Zoom in a MKMapView programmatically

后端 未结 9 1770
逝去的感伤
逝去的感伤 2020-12-04 13:27

I\'m using a MKMapView inside an iPhone app. When I click a button the zoom level must increase. This is my first approach:

MKCoordinateRegion z         


        
9条回答
  •  悲&欢浪女
    2020-12-04 13:57

    Just translated dkardel's solution to swift:

    @IBAction func zoomOutButtonClicked(sender: UIButton) {
        let span = MKCoordinateSpan(latitudeDelta: mapView.region.span.latitudeDelta*2, longitudeDelta: mapView.region.span.longitudeDelta*2)
        let region = MKCoordinateRegion(center: mapView.region.center, span: span)
    
        mapView.setRegion(region, animated: true)
    }
    
    @IBAction func zoomInButtonClicked(sender: UIButton) {
        let span = MKCoordinateSpan(latitudeDelta: mapView.region.span.latitudeDelta/2, longitudeDelta: mapView.region.span.longitudeDelta/2)
        let region = MKCoordinateRegion(center: mapView.region.center, span: span)
    
        mapView.setRegion(region, animated: true)
    }
    

提交回复
热议问题