Using IBAction Buttons to Zoom MapView

前端 未结 6 1546
谎友^
谎友^ 2021-01-02 17:17

I have an issue. My current location is displayed and centered in a map view however the map region doesn\'t get zoomed in to. I tried taking Rob\'s advice by taking span an

6条回答
  •  隐瞒了意图╮
    2021-01-02 18:03

    Try this. But I haven't tested yet.

    - (IBAction)zoomIn:(id)sender {
          MKCoordinateSpan span;
          span.latitudeDelta = _mapView.region.span.latitudeDelta * 2;
          span.longitudeDelta = _mapView.region.span.latitudeDelta * 2;
          MKCoordinateRegion region;
          region.span = span;
          region.center = _mapView.region.center;
    
         [self.mapView setRegion:region animated:YES];
     }
    
     - (IBAction)zoomOut:(id)sender {
          MKCoordinateSpan span;
          span.latitudeDelta = _mapView.region.span.latitudeDelta / 2;
          span.longitudeDelta = _mapView.region.span.latitudeDelta / 2;
          MKCoordinateRegion region;
          region.span = span;
          region.center = _mapView.region.center;
    
         [self.mapView setRegion:region animated:YES];
    
     }
    

提交回复
热议问题