Automatically scroll mkmapview when dragging a pin

Is there any good code that implements MKMapView auto-scroll when dragging a pin?

The effect I'm trying to achieve is scrolling the map when I drag the pin and reach the edge of the map. When I move the pin from the edges, I expect the scroll to stop, and when I reset it, move the shell of the shell until the contact reaches the center of the screen.

I know how to focus the map on a selected location, but I have no idea how to scroll it by dragging a pin.

It would really help if someone could just direct me to the logic of how to implement it.

+4
source share
1 answer
MKMapRect mapRect = [self.mapView visibleMapRect]; CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(42.777126,-76.113281); MKMapPoint point = MKMapPointForCoordinate(coordinate); mapRect.origin.x = point.x - mapRect.size.width * 0.3; mapRect.origin.y = point.y - mapRect.size.height * 0.70; [self.mapView setVisibleMapRect:mapRect animated:YES]; 
0
source

Source: https://habr.com/ru/post/1412135/


All Articles